问题描述
运行项目页面一片空白,报错
原因和解决方案:
router.beforeEach写在定义router之后
代码
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
router.beforeEach((to, from, next) => {
if (to.path !== '/null') {
if (localStorage.getItem("token")) {
next()
} else {
next("/null")
}
} else {
next()
}
})