请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

Error: Redirected from "/" to "{}" via a navigation guard.

const routes = [
{
path: ‘/’,
name: ‘Home’,
component: Home
},
{
path: ‘/login’,
name: ‘Login’,
component: Login
}
]

const router = createRouter({
history: createWebHashHistory(),
routes
})

router.beforeEach((to, from, next) => {
const isLogin = false
if (isLogin || to.name === ‘Login’) {
next()
} else { next({ name: ‘Login’ }) }
console.log(to, from)
next()
})

export default router

老师,想访问首页时控制台报的错误是
Error: Redirected from “/” to “{}” via a navigation guard.

请问这是什么原因呢?

正在回答 回答被采纳积分+3

1回答

Dell 2021-05-07 21:21:14

你在if 里面console.log 打印些东西,看走到哪段逻辑报的错误

0 回复 有任何疑惑可以回复我~
  • 提问者 学习web前端 #1
    好的,谢谢老师。我看看🧐
    回复 有任何疑惑可以回复我~ 2021-05-07 21:53:24
  • Stillpeng 回复 提问者 学习web前端 #2
    啥原因 找到了吗 我也出现了
    回复 有任何疑惑可以回复我~ 2021-08-11 09:57:41
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号