router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
if (!localStorage.token) {
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
} else {
next() // 确保一定要调用 next()
}
})
to.matched.some(record => record.meta.requiresAuth)这一段什莫意思啊 有大神知道吗
你可以看下 es6的 some方法。 这里的意思是,to.matched 的数组,如果在mate中有requiresAuth 那么就返回true