Commit c1178027f0fab2791d02efcd7c52beff5fc7dc25

Authored by 无木
1 parent db7254a5

fix: fix homePage affix error

修复当没有通过接口为用户指定首页时,如果默认的首页是一个带有重定向的路由,则可能出现双首页Tab的问题
src/router/routes/modules/about.ts
@@ -22,7 +22,7 @@ const dashboard: AppRouteModule = { @@ -22,7 +22,7 @@ const dashboard: AppRouteModule = {
22 meta: { 22 meta: {
23 title: t('routes.dashboard.about'), 23 title: t('routes.dashboard.about'),
24 icon: 'simple-icons:about-dot-me', 24 icon: 'simple-icons:about-dot-me',
25 - // hideMenu: true, 25 + hideMenu: true,
26 }, 26 },
27 }, 27 },
28 ], 28 ],
src/store/modules/permission.ts
@@ -123,15 +123,19 @@ export const usePermissionStore = defineStore({ @@ -123,15 +123,19 @@ export const usePermissionStore = defineStore({
123 * */ 123 * */
124 const patchHomeAffix = (routes: AppRouteRecordRaw[]) => { 124 const patchHomeAffix = (routes: AppRouteRecordRaw[]) => {
125 if (!routes || routes.length === 0) return; 125 if (!routes || routes.length === 0) return;
126 - const homePath = userStore.getUserInfo.homePath || PageEnum.BASE_HOME; 126 + let homePath: string = userStore.getUserInfo.homePath || PageEnum.BASE_HOME;
127 function patcher(routes: AppRouteRecordRaw[], parentPath = '') { 127 function patcher(routes: AppRouteRecordRaw[], parentPath = '') {
128 if (parentPath) parentPath = parentPath + '/'; 128 if (parentPath) parentPath = parentPath + '/';
129 routes.forEach((route: AppRouteRecordRaw) => { 129 routes.forEach((route: AppRouteRecordRaw) => {
130 - const { path, children } = route; 130 + const { path, children, redirect } = route;
131 const currentPath = path.startsWith('/') ? path : parentPath + path; 131 const currentPath = path.startsWith('/') ? path : parentPath + path;
132 if (currentPath === homePath) { 132 if (currentPath === homePath) {
133 - route.meta = Object.assign({}, route.meta, { affix: true });  
134 - throw new Error('end'); 133 + if (redirect) {
  134 + homePath = route.redirect! as string;
  135 + } else {
  136 + route.meta = Object.assign({}, route.meta, { affix: true });
  137 + throw new Error('end');
  138 + }
135 } 139 }
136 children && children.length > 0 && patcher(children, currentPath); 140 children && children.length > 0 && patcher(children, currentPath);
137 }); 141 });