Skip to content

Commit

Permalink
fix: exact property incorrent when using _routes.json, Close #160
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Mar 6, 2018
1 parent 93c9ec2 commit 34807af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion examples/routes-via-config/_routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
{
"path": "/list",
"exact": true,
"component": "./pages/b"
},
{
Expand Down
12 changes: 7 additions & 5 deletions packages/umi-build-dev/src/FilesGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ if (process.env.NODE_ENV === 'production') {
getRouterContent() {
const { routes, config, paths } = this.service;

const routesByPath = routes.reduce((memo, { path, component }) => {
memo[path] = component;
const routesByPath = routes.reduce((memo, route) => {
memo[route.path] = route;
return memo;
}, {});

Expand All @@ -208,7 +208,8 @@ if (process.env.NODE_ENV === 'production') {
)}').default,`;
}
let routesContent = Object.keys(routesByPath).map(key => {
const pageJSFile = winPath(relative(paths.tmpDirPath, routesByPath[key]));
const route = routesByPath[key];
const pageJSFile = winPath(relative(paths.tmpDirPath, route.component));
debug(`requested: ${JSON.stringify(getRequest())}`);
const isDev = process.env.NODE_ENV === 'development';

Expand All @@ -224,7 +225,7 @@ if (process.env.NODE_ENV === 'production') {
isCompiling = true;
}
} else {
webpackChunkName = normalizeEntry(routesByPath[key]);
webpackChunkName = normalizeEntry(route.component);
component = `dynamic(() => import(/* webpackChunkName: '${webpackChunkName}' */'${pageJSFile}'), { ${loadingOpts} })`;
}
component = this.service.applyPlugins('modifyRouteComponent', {
Expand All @@ -237,7 +238,8 @@ if (process.env.NODE_ENV === 'production') {
},
});

return ` <Route exact path="${key}" component={${component}} />`;
const exact = route.exact ? 'exact ' : '';
return ` <Route ${exact}path="${key}" component={${component}} />`;
});

routesContent = this.service.applyPlugins('modifyRoutesContent', {
Expand Down

0 comments on commit 34807af

Please sign in to comment.