当我从登录页/user/login 登录成功后跳转到dashboard/Analysis,页面报错Redirected when going from "xxxx" to "xxxxx" via a navigation guard.
各位大神是否遇到过??
代码如下:
routers.js
index.js
登录成功后跳转this.$router.push({ path: '/dashboard/Analysis' })
当我从登录页/user/login 登录成功后跳转到dashboard/Analysis,页面报错Redirected when going from "xxxx" to "xxxxx" via a navigation guard.
各位大神是否遇到过??
代码如下:
routers.js
index.js
登录成功后跳转this.$router.push({ path: '/dashboard/Analysis' })
13 回答12.9k 阅读
8 回答2.6k 阅读
2 回答5.1k 阅读✓ 已解决
9 回答1.7k 阅读✓ 已解决
5 回答1.3k 阅读
3 回答2.2k 阅读✓ 已解决
6 回答1.5k 阅读
1 回答10k 阅读
2.5k 阅读
1 回答6.3k 阅读✓ 已解决
8 回答27.4k 阅读✓ 已解决
7 回答22.6k 阅读
原因:
V3.1.0版本里面新增功能:push和replace方法会返回一个promise, 你可能在控制台看到未捕获的异常。
解决:
在你的routers.js中,引入Router后,对Router原型链上的push、replace方法进行重写,这样就不用每次调用方法都要加上catch。
import Router from 'vue-router'
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}