首页 > 解决方案 > React Router 组件有无功能的区别

问题描述

const PATH = BASE + '/' + id;
<Route path="PATH" render={PageContainer} /> (DOESN'T WORK for the case below)
<Route path="PATH" component={PageContainer} /> (DOESN'T WORK for the case below)
<Route path="PATH" component={ () => <PageContainer /> } /> (WORKS)

Steps:
1) go to the page BASE/1
2) go back to BASE
3) go to BASE/2

PageContainer connects to the store and passes props to Page.

为什么第二种方法有效,但第一种方法无效?

Update:     <Route path="PATH" render={PageContainer} /> (DOESN'T WORK for the case below)

标签: reactjsreact-routercontainersconnect

解决方案


尝试像这样访问它:

<Route path="PATH" component={PageContainer} /> 

组件和渲染道具之间存在差异。你可以在这里找到答案: react router difference between component and render


推荐阅读