使用 vue.router 重定向到绝对路径

Fru*_*ing 5 javascript routes vue.js vuetify.js

我能找到的所有示例都有助于管理应用程序内的路由,如下所示

this.$router.push({name: RouteName})
Run Code Online (Sandbox Code Playgroud)

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

this.$router.push({fullPath: https://google.com})
Run Code Online (Sandbox Code Playgroud)

但它什么也没做

dre*_*ker 9

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

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

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

但最好使用 vanilla js:

window.location.href = 'https://google.com';
Run Code Online (Sandbox Code Playgroud)