Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

Redirected when going from "x" to "x" via a navigation guard

当我从登录页/user/login 登录成功后跳转到dashboard/Analysis,页面报错Redirected when going from "xxxx" to "xxxxx" via a navigation guard.

各位大神是否遇到过??

代码如下:
routers.js
routers.js

index.js
index.js

登录成功后跳转
this.$router.push({ path: '/dashboard/Analysis' })


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

原因:
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)
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...