router
前置路由守卫
main.js 配置
import router from './router';const app = createApp(App);
app.use(router);
// 白名单
const whiteList = ['/'];
router.beforeEach((to, form, next) => {if (whiteList.includes(to.path) || localStorage.getItem('vue3Token')) {next();} else {next('/');}
});
app.mount('#app');
to: Route, 要进入的;
from: Route,从哪离开的;
next(): todo;
next(false): 中断当前的导航。
next('/') 或者 next({ path: '/' }): 跳转到一个不同的地址。
router
前置路由守卫
main.js 配置
import router from './router';const app = createApp(App);
app.use(router);
// 白名单
const whiteList = ['/'];
router.beforeEach((to, form, next) => {if (whiteList.includes(to.path) || localStorage.getItem('vue3Token')) {next();} else {next('/');}
});
app.mount('#app');
to: Route, 要进入的;
from: Route,从哪离开的;
next(): todo;
next(false): 中断当前的导航。
next('/') 或者 next({ path: '/' }): 跳转到一个不同的地址。