首页 > 解决方案 > 使用 vue.router 重定向到绝对路径

问题描述

我能找到的所有示例都有助于像这样管理应用程序内部的路由

this.$router.push({name: RouteName})

如果我想通过绝对路径进行重定向怎么办?我尝试

this.$router.push({fullPath: https://google.com})

但它什么也没做

标签: javascriptvue.jsroutesvuetify.js

解决方案


vue-router 专为在您的应用程序中进行路由而设计。使用它重定向到外部站点是没有意义的。

你仍然可以像这样使用 vue-router:

this.$router.push({ redirect: window.location.href = 'https://google.com' });

但最好使用 vanilla js:

window.location.href = 'https://google.com';

推荐阅读