fix: 动态刷新之后404

This commit is contained in:
JaguarJack 2023-02-23 09:38:48 +08:00
parent c73c68dee5
commit 8fd87ad46b
2 changed files with 8 additions and 8 deletions

View File

@ -41,10 +41,14 @@ const guard = (router: Router) => {
asyncRoutes.forEach((route: Menu) => { asyncRoutes.forEach((route: Menu) => {
router.addRoute(route as unknown as RouteRecordRaw) router.addRoute(route as unknown as RouteRecordRaw)
}) })
// 在动态路由之后挂载匹配 404 路由
router.addRoute({
path: '/:pathMatch(.*)*',
redirect: '/404',
})
} }
next({ ...to, replace: true }) next({ ...to, replace: true });
} catch (e) { } catch (e) {
console.log(e)
removeAuthToken() removeAuthToken()
next({ path: `${WhiteListPage.LOGIN_PATH}?redirect=/${to.path}` }) next({ path: `${WhiteListPage.LOGIN_PATH}?redirect=/${to.path}` })
} }
@ -54,6 +58,7 @@ const guard = (router: Router) => {
} else { } else {
// 如果不在白名单 // 如果不在白名单
if (whiteList.indexOf(to.path) !== -1) { if (whiteList.indexOf(to.path) !== -1) {
console.log(123)
next() next()
} else { } else {
next({ path: WhiteListPage.LOGIN_PATH }) next({ path: WhiteListPage.LOGIN_PATH })

View File

@ -43,12 +43,7 @@ const defaultRoutes: RouteRecordRaw[] = [
name: 'login', name: 'login',
meta: { title: '登录' }, meta: { title: '登录' },
component: () => import('/admin/views/login/index.vue'), component: () => import('/admin/views/login/index.vue'),
}, }
// 未定义路有重定向到 404
{
path: '/:pathMatch(.*)*',
redirect: '/404',
},
] ]
const routes = constantRoutes.concat(defaultRoutes) const routes = constantRoutes.concat(defaultRoutes)