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.
请问这是什么原因呢?