修复Breadcrumb.tsx 中处理route.children 路径不对

<Menu.Item key={child.breadcrumbName || child.path}>
                {itemRender(child, params, routes, [...paths, this.getPath(child.path, params)])}
</Menu.Item>
itemRender(...args) 中路径应该到拼接当前child.path
This commit is contained in:
haianweifeng 2019-05-30 17:06:59 +08:00 committed by GitHub
parent abb8692b59
commit 3122f3b86b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,6 +70,15 @@ export default class Breadcrumb extends React.Component<BreadcrumbProps, any> {
'see: https://u.ant.design/item-render.',
);
}
getPath = (path, params) => {
path = (path || '').replace(/^\//, '');
Object.keys(params).forEach(key => {
path = path.replace(`:${key}`, params[key]);
});
return path;
}
genForRoutes = ({
routes = [],
params = {},
@ -78,11 +87,7 @@ export default class Breadcrumb extends React.Component<BreadcrumbProps, any> {
}: BreadcrumbProps) => {
const paths: string[] = [];
return routes.map(route => {
route.path = route.path || '';
let path = route.path.replace(/^\//, '');
Object.keys(params).forEach(key => {
path = path.replace(`:${key}`, params[key]);
});
let path = this.getPath(route.path, params);
if (path) {
paths.push(path);
@ -94,7 +99,7 @@ export default class Breadcrumb extends React.Component<BreadcrumbProps, any> {
<Menu>
{route.children.map(child => (
<Menu.Item key={child.breadcrumbName || child.path}>
{itemRender(child, params, routes, paths)}
{itemRender(child, params, routes, [...paths, this.getPath(child.path, params)])}
</Menu.Item>
))}
</Menu>