如果路线发生变化,则更改React组件

时间:2016-02-17 14:05:42

标签: reactjs react-router redux

我正在使用react-redux-router。 我有以下代码:

<Router history={hashHistory}>
    <Route path="/" component={App}>
        <IndexRoute component={Home} />
        <Route path="/product/:id" component={Product} />
    </Route>
</Router>

当我的路线为“/”且路线为“/ product /:id”时,我想在App组件中显示不同的数据。如何在组件App中跟踪路径的变化。

1 个答案:

答案 0 :(得分:1)

使用react-router-redux的{​​{1}}中间件来保存路由。然后,您可以利用App组件中的syncHistoryconnect读取路径名并将其推送到道具。