[英]Change React component if route changes
i'm using react-redux-router. 我正在使用react-redux-router。 I have the following code:
我有以下代码:
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="/product/:id" component={Product} />
</Route>
</Router>
I want to show in App component different data when my route is "/" and when my route is "/product/:id". 当我的路线为“ /”和我的路线为“ / product /:id”时,我想在App组件中显示不同的数据。 How can I keep track of the change of route in component App.
如何在组件App中跟踪路线的变化。
Use react-router-redux
's syncHistory
middleware to keep route in store. 使用
react-router-redux
的syncHistory
中间件来保存路由。 Then you can utilize connect
in App component to read pathname from state.routing.location.pathname
and push it to props. 然后,您可以利用App组件中的
connect
从state.routing.location.pathname
读取路径名并将其推送到props。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.