404页面重定向到首页

This commit is contained in:
Xubx 2025-05-20 16:44:23 +08:00
parent a387b6abce
commit 386e7d085f
3 changed files with 15 additions and 3 deletions

View File

@ -194,7 +194,7 @@ export function createPermissionGuard(router: Router) {
// 添加重定向逻辑
if (to.name === PAGE_NOT_FOUND_ROUTE.name) {
// 如果是404页面尝试重定向到首页
// 如果是404页面重定向到首页
next({ path: userStore.getUserInfo.homePath || PageEnum.BASE_HOME, replace: true });
return;
}
@ -213,6 +213,12 @@ export function createPermissionGuard(router: Router) {
}
}
// 处理404页面
if (to.name === PAGE_NOT_FOUND_ROUTE.name) {
next({ path: userStore.getUserInfo.homePath || PageEnum.BASE_HOME, replace: true });
return;
}
next();
});
}

View File

@ -4,7 +4,7 @@ import type { Router, RouteRecordNormalized } from 'vue-router';
import { getParentLayout, LAYOUT, EXCEPTION_COMPONENT } from '/@/router/constant';
import { cloneDeep, omit } from 'lodash-es';
import { warn } from '/@/utils/log';
import { createRouter, createWebHashHistory } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import { getTenantId, getToken } from "/@/utils/auth";
import { URL_HASH_TAB, _eval } from '/@/utils';
//引入online lib路由
@ -174,7 +174,7 @@ function promoteRouteLevel(routeModule: AppRouteModule) {
// Use vue-router to splice menus
let router: Router | null = createRouter({
routes: [routeModule as unknown as RouteRecordNormalized],
history: createWebHashHistory(),
history: createWebHistory(),
});
const routes = router.getRoutes();

View File

@ -1,6 +1,8 @@
import type { AppRouteRecordRaw } from '/@/router/types';
import { t } from '/@/hooks/web/useI18n';
import { REDIRECT_NAME, LAYOUT, EXCEPTION_COMPONENT, PAGE_NOT_FOUND_NAME } from '/@/router/constant';
import { useUserStoreWithOut } from '/@/store/modules/user';
import { PageEnum } from '/@/enums/pageEnum';
// 404 on a page
export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
@ -22,6 +24,10 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
hideBreadcrumb: true,
hideMenu: true,
},
beforeEnter: (to, from, next) => {
const userStore = useUserStoreWithOut();
next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
},
},
],
};