Reactjs React路由器4 React路由器配置防止组件卸载

Reactjs React路由器4 React路由器配置防止组件卸载,reactjs,react-router,Reactjs,React Router,我正在我的同构react应用程序中使用来自react路由器配置的renderRoutes()函数。我的情况是,同一个组件有多个端点。每次用户导航到新端点时,我都需要获取该端点的数据并将其呈现给组件。通常,我会通过组件willreceiveprops()执行此操作,然后根据新URL发出AJAX请求。但是,每次我导航到不同的端点时,组件都会被卸载和重新装载。有没有一种方法可以防止组件被卸载,而只是更新其属性 export const routes = [ { component: Secti

我正在我的同构react应用程序中使用来自react路由器配置的
renderRoutes()
函数。我的情况是,同一个组件有多个端点。每次用户导航到新端点时,我都需要获取该端点的数据并将其呈现给组件。通常,我会通过
组件willreceiveprops()
执行此操作,然后根据新URL发出AJAX请求。但是,每次我导航到不同的端点时,组件都会被卸载和重新装载。有没有一种方法可以防止组件被卸载,而只是更新其属性

export const routes = [
{
    component: SectionFront,
    path: '/' ,
    exact: true,
    loadData: ( match ) =>{      
    return loadSectionFront( match.path )
    },
    },{
    component: SectionFront,
    path: '/investing' ,
    exact: false,
    loadData: ( match ) =>{
    return loadSectionFront( match.path )
    }
},
{
    component: SectionFront,
    path: '/news/companies' ,
    exact: false,
    loadData: ( match ) =>{
    return loadSectionFront( match.path )
    }
}]

ReactDOM.render(
    <Provider store={store}>
        <BrowserRouter>
          <CoreLayout>
            {renderRoutes(routes)}
          </CoreLayout>
        </BrowserRouter>
     </Provider>,
    mountNode
  );
导出常量路由=[
{
组件:SectionFront,
路径:“/”,
确切地说:是的,
loadData:(匹配)=>{
返回loadSectionFront(match.path)
},
},{
组件:SectionFront,
路径:'/investing',
准确:错,
loadData:(匹配)=>{
返回loadSectionFront(match.path)
}
},
{
组件:SectionFront,
路径:'/news/companys',
准确:错,
loadData:(匹配)=>{
返回loadSectionFront(match.path)
}
}]
ReactDOM.render(
{renderRoutes(routes)}
,
mountNode
);

问题似乎与
react router config
本身有关。根据its的源代码,由于
开关
组件包装传递的路由,它始终只呈现一条
路由


我认为,对于从配置方法创建路由,您必须提供自己的解决方案

你能找到解决办法吗?