// 重定向自定义
router.beforeEach(async(to, from, next) => {
if (to.path == '/') {
const data = await getAllNeedRoutes()
console.log(to,'to')
console.log(data, 'data')
// , query: JSON.stringify(to.query)
next({ path: data, query: to.query });
return
}
if (sessionStorage.getItem('token')) {
next()
} else {
next()
}
notice:
这里我还遇到一个问题 就是路由死循环 切记导航守卫每一个分支都需要经过next()
next(参数)于next()完全不一样
next()不会再次调用beforeEach; next(参数)会再次调用beforeEach 不小心就会进入死循环