Skip to content

Commit

Permalink
fix: wirte route bug when has redirect (#2467)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu authored and sorrycc committed May 25, 2019
1 parent 116e1c7 commit 5502704
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export default {
path: '/aa',
component: 'aa',
routes: [
{
path: '/aa',
redirect: '/testredirect',
},
{
path: '/aa/vv',
name: 'dd',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export default {
path: '/aa',
component: 'aa',
routes: [
{
path: '/aa',
redirect: '/testredirect',
},
{
path: '/aa/vv',
name: 'dd',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export default {
path: '/aa',
component: 'aa',
routes: [
{
path: '/aa',
redirect: '/testredirect',
},
{
path: '/aa/vv',
name: 'dd',
Expand Down
8 changes: 7 additions & 1 deletion packages/umi-build-dev/src/utils/writeNewRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export function writeRouteNode(targetNode, newRoute, currentPath = '/') {
return false;
}
const { properties } = ele;
const redirect = properties.find(p => {
return p.key.name === 'redirect';
});
if (redirect) {
return false;
}
const pathProp = properties.find(p => {
return p.key.name === 'path';
});
Expand All @@ -146,7 +152,7 @@ export function writeRouteNode(targetNode, newRoute, currentPath = '/') {
debug('paths', paths);

const matchedIndex = paths.findIndex(p => {
return newRoute.path.indexOf(p) === 0;
return p && newRoute.path.indexOf(p) === 0;
});

const newNode = getNewRouteNode(newRoute);
Expand Down

0 comments on commit 5502704

Please sign in to comment.