Skip to content

Commit

Permalink
fix #1129 / memorize withRoutes in renderRoutes.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Wensheng Xu committed Oct 12, 2018
1 parent 5d07ae1 commit d466112
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/umi/src/renderRoutes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';

const RouteInstanceMap = {
remove(key) {
key._routeInternalComponent = undefined;
},
get(key) {
return key._routeInternalComponent;
},
has(key) {
return key._routeInternalComponent !== undefined;
},
set(key, value) {
key._routeInternalComponent = value;
},
};

function withRoutes(route) {
if (RouteInstanceMap.has(route)) {
return RouteInstanceMap.get(route);
}

const Routes = route.Routes;
let len = Routes.length - 1;
let Component = args => {
Expand All @@ -19,7 +38,7 @@ function withRoutes(route) {
len -= 1;
}

return args => {
const ret = args => {
const { render, ...rest } = args;
return (
<Route
Expand All @@ -30,6 +49,8 @@ function withRoutes(route) {
/>
);
};
RouteInstanceMap.set(route, ret);
return ret;
}

export default function renderRoutes(
Expand Down

0 comments on commit d466112

Please sign in to comment.