| | |
| | | const userStore = useUserStoreWithOut(); |
| | | const permissionStore = usePermissionStoreWithOut(); |
| | | router.beforeEach(async (to, from, next) => { |
| | | // Jump to the 404 page after processing the login |
| | | if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_ROUTE.name) { |
| | | next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME); |
| | | return; |
| | | } |
| | | |
| | | if ( |
| | | from.path === ROOT_PATH && |
| | | to.path === PageEnum.BASE_HOME && |
| | |
| | | return; |
| | | } |
| | | |
| | | // Jump to the 404 page after processing the login |
| | | if ( |
| | | from.path === LOGIN_PATH && |
| | | to.name === PAGE_NOT_FOUND_ROUTE.name && |
| | | to.fullPath !== (userStore.getUserInfo.homePath || PageEnum.BASE_HOME) |
| | | ) { |
| | | next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME); |
| | | return; |
| | | } |
| | | |
| | | // get userinfo while last fetch time is empty |
| | | if (userStore.getLastUpdateTime === 0) { |
| | | try { |
| | | await userStore.getUserInfoAction(); |
| | | } catch (err) { |
| | | next(); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | if (permissionStore.getIsDynamicAddedRoute) { |
| | | next(); |
| | | return; |
| | |
| | | |
| | | if (to.name === PAGE_NOT_FOUND_ROUTE.name) { |
| | | // 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容 |
| | | next({ path: to.fullPath, replace: true }); |
| | | next({ path: to.fullPath, replace: true, query: to.query }); |
| | | } else { |
| | | const redirectPath = (from.query.redirect || to.path) as string; |
| | | const redirect = decodeURIComponent(redirectPath); |