如果在地址栏手动输入不存在的地址,直接跳转至404,在路由拦截里面做判断,写个demo:
router.beforeEach((to, from, next) => {
if (store.state.CandyHouse.token) {
if (to.path == '/login') {
next({path: '/'});
} else {
if (to.matched.length === 0) {
next("/404");
} else {
next();
}
}
} else {
if (to.path == '/login') {
next();
} else {
next({path: '/login'});
}
}
})