feat(projects): new router system [新的路由系统]

This commit is contained in:
Soybean
2022-11-08 01:14:59 +08:00
parent 40c1e13b50
commit c7b6a3fbec
54 changed files with 1328 additions and 759 deletions

View File

@@ -18,7 +18,7 @@ export async function createDynamicRouteGuard(
if (!route.isInitAuthRoute) {
// 未登录情况下直接回到登录页,登录成功后再加载权限路由
if (!isLogin) {
const toName = to.name as AuthRoute.RouteKey;
const toName = to.name as AuthRoute.AllRouteKey;
if (route.isValidConstantRoute(toName) && !to.meta.requiresAuth) {
next();
} else {
@@ -30,19 +30,19 @@ export async function createDynamicRouteGuard(
await route.initAuthRoute();
if (to.name === routeName('not-found-page')) {
// 动态路由没有加载导致被not-found-page路由捕获,等待权限路由加载好了,回到之前的路由
if (to.name === routeName('not-found')) {
// 动态路由没有加载导致被not-found路由捕获等待权限路由加载好了回到之前的路由
// 若路由是从根路由重定向过来的,重新回到根路由
const ROOT_ROUTE_NAME: AuthRoute.RouteKey = 'root';
const ROOT_ROUTE_NAME: AuthRoute.AllRouteKey = 'root';
const path = to.redirectedFrom?.name === ROOT_ROUTE_NAME ? '/' : to.fullPath;
next({ path, replace: true, query: to.query, hash: to.hash });
return false;
}
}
// 权限路由已经加载,仍然未找到,重定向到not-found
if (to.name === routeName('not-found-page')) {
next({ name: routeName('not-found'), replace: true });
// 权限路由已经加载,仍然未找到,重定向到404
if (to.name === routeName('not-found')) {
next({ name: routeName('404'), replace: true });
return false;
}

View File

@@ -61,7 +61,7 @@ export async function createPermissionGuard(
// 登录状态进入需要登录权限的页面,无权限,重定向到无权限页面
isLogin && needLogin && !hasPermission,
() => {
next({ name: routeName('no-permission') });
next({ name: routeName('403') });
}
]
];