Skip to content

Commit

Permalink
fix:修复 动态路由匹配
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed Jun 21, 2023
1 parent 86bcd89 commit 4d332d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
6 changes: 6 additions & 0 deletions examples/basic/config/router.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"path": "/",
"redirectTo": "/welcome"
},
{
"path": "/doc/:id",
"name": "首页21",
"icon": "welcome",
"component": "@/pages/index"
},
{
"path": "/welcome",
"name": "首页",
Expand Down
47 changes: 30 additions & 17 deletions packages/basic-layouts/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ItemType } from 'antd/lib/menu/hooks/useItems';
import React from 'react';
import { IntlShape } from 'react-intl/lib/src/types';
import { NavLink } from 'react-router-dom';
// @ts-ignore
import { matchRoutes } from '@umijs/max';
import { HandleMenuProps, RouterMenu } from './interface';

/**
Expand Down Expand Up @@ -256,13 +258,20 @@ export class HandleMenu {

/**9. 获取跳转地址*/
getToPath(path: string) {

let [currentItem] = matchRoutes(this.flatAllMenu, path)

if (currentItem && currentItem.route) {
currentItem = currentItem.route
}
// 1. 先判断是不是 side === true
const currentItem = this.flatAllMenu.find((item) => item.path === path);
// const currentItem = this.flatAllMenu.find((item) => item.path === path);
if (currentItem?.path === '/') {
this.preParentPath = '';
this.prePath = currentItem.redirectTo;
return currentItem.redirectTo;
}

if (!currentItem) {
this.preParentPath = '';
if (this.prePath === '/404') {
Expand All @@ -271,12 +280,14 @@ export class HandleMenu {
this.prePath = '/404';
return '/404';
}

// 查询所有父节点和自己是否有权限
if (!!ANTD_AUTH_CONF && !this.getCheckAuthAll(currentItem?.path || '')) {
this.prePath = '/403';
this.preParentPath = '';
return '/403';
}

if (!currentItem?.side) {
this.prePath = currentItem.path || '';
this.preParentPath = '';
Expand All @@ -288,8 +299,10 @@ export class HandleMenu {
}
this.preParentPath = currentItem.path;
const siderMenus = this.childMenu.get(path);

const findx = siderMenus?.find((item) => item.index || item.redirectTo);
const current = findx?.path || findx?.redirectTo;

if (this.prePath === current) {
return false;
}
Expand Down Expand Up @@ -368,14 +381,14 @@ export const themeColor = {
'--primary-header-text-color': '#1d1d1d',
'--primary-title-text-color': '#1d1d1d',
'--primary-content-bg': '#f5f5f5',
'itemSelectedBg':'#e6f7ff',
'colorItemBgSelected':'rgba(0, 0, 0, 0.06)',
'itemActiveBg':'#e6f7ff',
'horizontalItemSelectedBg':'rgba(0, 0, 0, 0.06)',
'itemColor':'rgba(0, 0, 0, 0.65)',
'itemHoverColor':'rgba(0, 0, 0, 0.85)',
'itemSelectedColor':'rgb(24, 144, 255)',
'colorBgElevated':'#fff',
'itemSelectedBg': '#e6f7ff',
'colorItemBgSelected': 'rgba(0, 0, 0, 0.06)',
'itemActiveBg': '#e6f7ff',
'horizontalItemSelectedBg': 'rgba(0, 0, 0, 0.06)',
'itemColor': 'rgba(0, 0, 0, 0.65)',
'itemHoverColor': 'rgba(0, 0, 0, 0.85)',
'itemSelectedColor': 'rgb(24, 144, 255)',
'colorBgElevated': '#fff',
},
dark: {
'--primary-slider-bg': '#1d1d1d',
Expand All @@ -386,13 +399,13 @@ export const themeColor = {
'--primary-header-text-color': '#fff',
'--primary-title-text-color': '#fff',
'--primary-content-bg': '#1d1d1d',
'itemSelectedBg':'rgb(24, 144, 255)',
'colorItemBgSelected':'#fff',
'itemActiveBg':'#fff',
'horizontalItemSelectedBg':'#fff',
'itemColor':'rgba(229, 224, 216, 0.85)',
'itemHoverColor':'rgba(229, 224, 216, 0.85)',
'itemSelectedColor':'#fff',
'colorBgElevated':'rgba(229, 224, 216, 0.85)',
'itemSelectedBg': 'rgb(24, 144, 255)',
'colorItemBgSelected': '#fff',
'itemActiveBg': '#fff',
'horizontalItemSelectedBg': '#fff',
'itemColor': 'rgba(229, 224, 216, 0.85)',
'itemHoverColor': 'rgba(229, 224, 216, 0.85)',
'itemSelectedColor': '#fff',
'colorBgElevated': 'rgba(229, 224, 216, 0.85)',
},
};

0 comments on commit 4d332d8

Please sign in to comment.