【issues/7500】vue-router4.5.0版本路由name:PageNotFound同名导致登录进不去

pull/7524/head
JEECG 2024-11-27 18:41:24 +08:00
parent 32c8370ef2
commit e2aaf0f978
4 changed files with 20 additions and 10 deletions

View File

@ -3,6 +3,9 @@ export const REDIRECT_NAME = 'Redirect';
export const PARENT_LAYOUT_NAME = 'ParentLayout'; export const PARENT_LAYOUT_NAME = 'ParentLayout';
export const PAGE_NOT_FOUND_NAME = 'PageNotFound'; export const PAGE_NOT_FOUND_NAME = 'PageNotFound';
// update-begin--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
export const PAGE_NOT_FOUND_NAME_404 = 'PageNotFound404';
// update-end--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
export const EXCEPTION_COMPONENT = () => import('/@/views/sys/exception/Exception.vue'); export const EXCEPTION_COMPONENT = () => import('/@/views/sys/exception/Exception.vue');

View File

@ -12,6 +12,7 @@ import { RootRoute } from '/@/router/routes';
import { isOAuth2AppEnv } from '/@/views/sys/login/useLogin'; import { isOAuth2AppEnv } from '/@/views/sys/login/useLogin';
import { OAUTH2_THIRD_LOGIN_TENANT_ID } from "/@/enums/cacheEnum"; import { OAUTH2_THIRD_LOGIN_TENANT_ID } from "/@/enums/cacheEnum";
import { setAuthCache } from "/@/utils/auth"; import { setAuthCache } from "/@/utils/auth";
import { PAGE_NOT_FOUND_NAME_404 } from '/@/router/constant';
const LOGIN_PATH = PageEnum.BASE_LOGIN; const LOGIN_PATH = PageEnum.BASE_LOGIN;
//auth2 //auth2
@ -162,12 +163,13 @@ export function createPermissionGuard(router: Router) {
return; return;
} }
//================================================ //================================================
// update-begin--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
// Jump to the 404 page after processing the login // 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)) { if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_NAME_404 && to.fullPath !== (userStore.getUserInfo.homePath || PageEnum.BASE_HOME)) {
next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME); next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
return; return;
} }
// update-end--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
//update-begin---author:scott ---date:2024-02-21 forQQYUN-8326--- //update-begin---author:scott ---date:2024-02-21 forQQYUN-8326---
// // get userinfo while last fetch time is empty // // get userinfo while last fetch time is empty
@ -199,8 +201,8 @@ export function createPermissionGuard(router: Router) {
router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw); router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);
permissionStore.setDynamicAddedRoute(true); permissionStore.setDynamicAddedRoute(true);
// update-begin--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
if (to.name === PAGE_NOT_FOUND_ROUTE.name) { if (to.name === PAGE_NOT_FOUND_NAME_404) {
// fullPath404 // fullPath404
next({ path: to.fullPath, replace: true, query: to.query }); next({ path: to.fullPath, replace: true, query: to.query });
} else { } else {
@ -209,5 +211,6 @@ export function createPermissionGuard(router: Router) {
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }; const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
next(nextData); next(nextData);
} }
// update-end--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
}); });
} }

View File

@ -1,13 +1,12 @@
import type { AppRouteRecordRaw } from '/@/router/types'; import type { AppRouteRecordRaw } from '/@/router/types';
import { t } from '/@/hooks/web/useI18n'; import { t } from '/@/hooks/web/useI18n';
import { REDIRECT_NAME, LAYOUT, EXCEPTION_COMPONENT, PAGE_NOT_FOUND_NAME } from '/@/router/constant'; import { REDIRECT_NAME, LAYOUT, EXCEPTION_COMPONENT, PAGE_NOT_FOUND_NAME, PAGE_NOT_FOUND_NAME_404 } from '/@/router/constant';
// 404 on a page // 404 on a page
export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = { export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
path: '/:path(.*)*', path: '/:path(.*)*',
// update-begin--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
name: 'PageNotFound404', name: PAGE_NOT_FOUND_NAME,
// update-end--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
component: LAYOUT, component: LAYOUT,
meta: { meta: {
title: 'ErrorPage', title: 'ErrorPage',
@ -17,7 +16,9 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
children: [ children: [
{ {
path: '/:path(.*)*', path: '/:path(.*)*',
name: PAGE_NOT_FOUND_NAME, // update-begin--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
name: PAGE_NOT_FOUND_NAME_404,
// update-end--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
component: EXCEPTION_COMPONENT, component: EXCEPTION_COMPONENT,
meta: { meta: {
title: 'ErrorPage', title: 'ErrorPage',

View File

@ -3,6 +3,7 @@ import type { RouteLocationNormalized, RouteLocationRaw, Router } from 'vue-rout
import { toRaw, unref } from 'vue'; import { toRaw, unref } from 'vue';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { store } from '/@/store'; import { store } from '/@/store';
import { PAGE_NOT_FOUND_NAME_404 } from '/@/router/constant';
import { useGo, useRedo } from '/@/hooks/web/usePage'; import { useGo, useRedo } from '/@/hooks/web/usePage';
import { Persistent } from '/@/utils/cache/persistent'; import { Persistent } from '/@/utils/cache/persistent';
@ -152,15 +153,17 @@ export const useMultipleTabStore = defineStore({
async addTab(route: RouteLocationNormalized) { async addTab(route: RouteLocationNormalized) {
const { path, name, fullPath, params, query, meta } = getRawRoute(route); const { path, name, fullPath, params, query, meta } = getRawRoute(route);
// update-begin--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
// 404 The page does not need to add a tab // 404 The page does not need to add a tab
if ( if (
path === PageEnum.ERROR_PAGE || path === PageEnum.ERROR_PAGE ||
path === PageEnum.BASE_LOGIN || path === PageEnum.BASE_LOGIN ||
!name || !name ||
[REDIRECT_ROUTE.name, PAGE_NOT_FOUND_ROUTE.name].includes(name as string) [REDIRECT_ROUTE.name, PAGE_NOT_FOUND_NAME_404].includes(name as string)
) { ) {
return; return;
} }
// update-end--author:liaozhiyang---date:202401127---forissues/7500vue-router4.5.0name:PageNotFound
let updateIndex = -1; let updateIndex = -1;
// Existing pages, do not add tabs repeatedly // Existing pages, do not add tabs repeatedly