在项目中,会遇到相同的路由,可能需要使用相同的页面(容器组件),如果点不同的路由需要重新查询,但是发现没有重新进容器的渲染周期,代码如下:

 export default ({match}) => (
    <Switch>
        <Route path={`${match.url}/med-library`} component={medicineLibraryViews.MedLibrary} />
        <Route path={`${match.url}/trans-library`} component={transLibraryViews.MedLibrary} />
        <Redirect to="/404"/>
    </Switch> 
); 

最后通过给两个相同的route设置不同的key渲染解决,修改后代码如下:

export default ({match}) => (
    <Switch>
        <Route path={`${match.url}/med-library`} component={medicineLibraryViews.MedLibrary} key='/med-library' />
        <Route path={`${match.url}/trans-library`} component={transLibraryViews.MedLibrary} key='/trans-library'/>
        <Redirect to="/404"/>
    </Switch> 
); 

 

相关文章:

  • 2021-05-25
  • 2020-10-12
  • 2021-06-25
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
相关资源
相似解决方案