// main.js
<Provider store={store}>
<Router history={history}>
<App>
<Switch>
<Redirect key='index' from='/' exact to='home'/>
{
_.map(routes, (route, i) => {
const {store, path, component, exact, redirectTo} = route;
if (redirectTo) {
return <Redirect key={path} path={path} to={redirectTo}/>;
}
let routeConfig = {
path,
exact,
render: props => {
return (
<RouteBundle load={component}>
{Comp => Comp ? (<Comp {...props} />) : null}
</RouteBundle>
);
}
};
return <Route key={path} {...routeConfig}/>;
})
}
<Route key='notFound' component={NotFound}/>
</Switch>
</App>
</Router>
</Provider>
对于Route组件将创建子组件的新实例,它来自浏览器的Endless Loop重绘。我知道由<App>
组件的错误位置引起的BUG。
但是,只有当process.env.NODE_ENV
的值为生产时,BUG才会重现。 WHY ???
// in webpack file
new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify('production')}),