当我从登录页/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' })
10 回答11.2k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答4.8k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
2 回答4.8k 阅读✓ 已解决
1 回答9.9k 阅读
2.5k 阅读
1 回答6.2k 阅读✓ 已解决
8 回答27.2k 阅读✓ 已解决
7 回答22.4k 阅读
原因:
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)
}