2017-06-16 345 views
0

我在我的同構反應應用程序中使用react-router-configrenderRoutes()函數。我有一個情況,就是同一個組件有很多端點。每次用戶導航到新端點時,我需要爲該端點提取數據並將其呈現給組件。通常我會通過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 
); 

回答

0

看起來問題與react-router-config本身有關。根據其renderRoutes routine的源代碼,由於Switch組件包裝傳遞的路由,它總是隻會呈現一個Route

我想你將不得不爲你的解決方案配置create-routes-from-config方法。