Skip to content

Commit

Permalink
fix: fix homePage affix error
Browse files Browse the repository at this point in the history
修复当没有通过接口为用户指定首页时,如果默认的首页是一个带有重定向的路由,则可能出现双首页Tab的问题
  • Loading branch information
mynetfan committed Jul 15, 2021
1 parent db7254a commit c117802
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/router/routes/modules/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const dashboard: AppRouteModule = {
meta: {
title: t('routes.dashboard.about'),
icon: 'simple-icons:about-dot-me',
// hideMenu: true,
hideMenu: true,
},
},
],
Expand Down
12 changes: 8 additions & 4 deletions src/store/modules/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,19 @@ export const usePermissionStore = defineStore({
* */
const patchHomeAffix = (routes: AppRouteRecordRaw[]) => {
if (!routes || routes.length === 0) return;
const homePath = userStore.getUserInfo.homePath || PageEnum.BASE_HOME;
let homePath: string = userStore.getUserInfo.homePath || PageEnum.BASE_HOME;
function patcher(routes: AppRouteRecordRaw[], parentPath = '') {
if (parentPath) parentPath = parentPath + '/';
routes.forEach((route: AppRouteRecordRaw) => {
const { path, children } = route;
const { path, children, redirect } = route;
const currentPath = path.startsWith('/') ? path : parentPath + path;
if (currentPath === homePath) {
route.meta = Object.assign({}, route.meta, { affix: true });
throw new Error('end');
if (redirect) {
homePath = route.redirect! as string;
} else {
route.meta = Object.assign({}, route.meta, { affix: true });
throw new Error('end');
}
}
children && children.length > 0 && patcher(children, currentPath);
});
Expand Down

0 comments on commit c117802

Please sign in to comment.