diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 3ba0ad3c6676cff64d3892f5e2c097618325c618..307a15b67fb19f2faa1df91c85c47a0b46d23bd3 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -203,6 +203,15 @@ class BasicLayout extends React.PureComponent { }); 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) => { const lastOpenKey = openKeys[openKeys.length - 1]; const isMainMenu = this.menus.some( @@ -239,7 +248,7 @@ class BasicLayout extends React.PureComponent { } } render() { - const { app, currentUser, collapsed, fetchingNotices } = this.props; + const { currentUser, collapsed, fetchingNotices } = this.props; const menu = ( @@ -352,7 +361,7 @@ class BasicLayout extends React.PureComponent { exact={item.exact} key={item.path} path={item.path} - component={item.component(app)} + component={this.getRouteComponent(item)} /> ) ) diff --git a/src/layouts/UserLayout.js b/src/layouts/UserLayout.js index c6212a568a81d345a1647264c3a66cbe38225503..0eb560053ee3274726cc64ba7374e147196eea06 100644 --- a/src/layouts/UserLayout.js +++ b/src/layouts/UserLayout.js @@ -39,6 +39,15 @@ class UserLayout extends React.PureComponent { }); 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() { return ( @@ -59,7 +68,7 @@ class UserLayout extends React.PureComponent { exact={item.exact} key={item.path} path={item.path} - component={item.component(this.props.app)} + component={this.getRouteComponent()} /> ) )