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
);