Commit cc7212e1 authored by afc163's avatar afc163

Fix dynamic component remount, #114

parent 5c6de669
...@@ -203,6 +203,15 @@ class BasicLayout extends React.PureComponent { ...@@ -203,6 +203,15 @@ class BasicLayout extends React.PureComponent {
}); });
return groupBy(newNotices, 'type'); return groupBy(newNotices, 'type');
} }
getRouteComponent(item) {
if (this.routeComponents[item.path]) {
return this.routeComponents[item.path];
}
const component = item.component(this.props.app);
this.routeComponents[item.path] = component;
return component;
}
routeComponents = {};
handleOpenChange = (openKeys) => { handleOpenChange = (openKeys) => {
const lastOpenKey = openKeys[openKeys.length - 1]; const lastOpenKey = openKeys[openKeys.length - 1];
const isMainMenu = this.menus.some( const isMainMenu = this.menus.some(
...@@ -239,7 +248,7 @@ class BasicLayout extends React.PureComponent { ...@@ -239,7 +248,7 @@ class BasicLayout extends React.PureComponent {
} }
} }
render() { render() {
const { app, currentUser, collapsed, fetchingNotices } = this.props; const { currentUser, collapsed, fetchingNotices } = this.props;
const menu = ( const menu = (
<Menu className={styles.menu} selectedKeys={[]} onClick={this.onMenuClick}> <Menu className={styles.menu} selectedKeys={[]} onClick={this.onMenuClick}>
...@@ -352,7 +361,7 @@ class BasicLayout extends React.PureComponent { ...@@ -352,7 +361,7 @@ class BasicLayout extends React.PureComponent {
exact={item.exact} exact={item.exact}
key={item.path} key={item.path}
path={item.path} path={item.path}
component={item.component(app)} component={this.getRouteComponent(item)}
/> />
) )
) )
......
...@@ -39,6 +39,15 @@ class UserLayout extends React.PureComponent { ...@@ -39,6 +39,15 @@ class UserLayout extends React.PureComponent {
}); });
return title; return title;
} }
getRouteComponent(item) {
if (this.routeComponents[item.path]) {
return this.routeComponents[item.path];
}
const component = item.component(this.props.app);
this.routeComponents[item.path] = component;
return component;
}
routeComponents = {};
render() { render() {
return ( return (
<DocumentTitle title={this.getPageTitle()}> <DocumentTitle title={this.getPageTitle()}>
...@@ -59,7 +68,7 @@ class UserLayout extends React.PureComponent { ...@@ -59,7 +68,7 @@ class UserLayout extends React.PureComponent {
exact={item.exact} exact={item.exact}
key={item.path} key={item.path}
path={item.path} path={item.path}
component={item.component(this.props.app)} component={this.getRouteComponent()}
/> />
) )
) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment