|
|
|
@ -13,14 +13,19 @@ const WHITE_NAME_LIST: string[] = [
|
|
|
|
|
function createRouterGuards(router: Router) { |
|
|
|
|
const userStore = useUserStore() |
|
|
|
|
// 前置
|
|
|
|
|
router.beforeEach(async (to, _from, next) => { |
|
|
|
|
router.beforeEach(async (to, from, next) => { |
|
|
|
|
const isErrorPage = router.getRoutes().findIndex(item => item.name === to.name) |
|
|
|
|
if (isErrorPage === -1) |
|
|
|
|
next({ name: PageEnum.ERROR_PAGE_NAME_404 }) |
|
|
|
|
|
|
|
|
|
if (userStore.getToken) { |
|
|
|
|
if (WHITE_NAME_LIST.includes(to.name as string)) { |
|
|
|
|
next({ name: from.name as string }) |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
next() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
if (WHITE_NAME_LIST.includes(to.name as string)) |
|
|
|
|
next() |
|
|
|
|