javascript - 使用 vue.router 重定向到绝对路径
问题描述
我能找到的所有示例都有助于像这样管理应用程序内部的路由
this.$router.push({name: RouteName})
如果我想通过绝对路径进行重定向怎么办?我尝试
this.$router.push({fullPath: https://google.com})
但它什么也没做
解决方案
vue-router 专为在您的应用程序中进行路由而设计。使用它重定向到外部站点是没有意义的。
你仍然可以像这样使用 vue-router:
this.$router.push({ redirect: window.location.href = 'https://google.com' });
但最好使用 vanilla js:
window.location.href = 'https://google.com';
推荐阅读
- django - 更改 Django Createview 中的默认破折号
- asp.net-mvc - 在 Asp.Net MVC 应用程序中每个请求调用一次 SaveChanges
- javascript - 如何将变量重置为默认值?
- javascript - JQuery AJAX,成功时从表中删除,不成功时保留
- c# - 有没有办法覆盖类中的 app.config 设置(C#)
- python - 带有 altair 的简单折线图
- java - 更新到最新依赖后的 Firestore 错误
- javascript - 减少 redux-thunk 样板代码
- javascript - 带有 JSON 数据源的自动完成文本框
- c++ - 有没有办法删除传递给函数 `foo (new Object())` 的对象?