0
我在我的同构反应应用程序中使用react-router-config
的renderRoutes()
函数。我有一个情况,就是同一个组件有很多端点。每次用户导航到新端点时,我需要为该端点提取数据并将其呈现给组件。通常我会通过componentWillReceiveProps()
这样做,然后根据新的URL发起AJAX请求。但是,每次我导航到不同的端点时,组件都将被卸载并重新安装。有没有办法阻止组件被卸载,只是它的属性更新?反应路由器4 react-router-config防止组件从卸载
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
);