Javascript React router:使用hashHistory.push刷新子页面内容
我正在做一个SPA,它使用react路由器,如下所示:Javascript React router:使用hashHistory.push刷新子页面内容,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我正在做一个SPA,它使用react路由器,如下所示: <Router> <Route path="/" component={Base}> <IndexRoute component={Home}/> <Route path="features/:id" component={Single} /> </Route> </Router> 页面url更新成功,但一旦我进入子路由,对hashHi
<Router>
<Route path="/" component={Base}>
<IndexRoute component={Home}/>
<Route path="features/:id" component={Single} />
</Route>
</Router>
页面url更新成功,但一旦我进入子路由,对hashHistory的更改不会导致子状态更新。您知道如何在此处重新加载内容吗?您需要添加。这将响应所有渲染
的道具更改,初始渲染除外。回想一下,所有来自路由器的东西实际上只是一个道具
// Example: the feature id changed in the url
componentWillReceiveProps(nextProps) {
if (this.props.params.id !== nextProps.params.id) {
this.setState(...);
}
}
// Example: the feature id changed in the url
componentWillReceiveProps(nextProps) {
if (this.props.params.id !== nextProps.params.id) {
this.setState(...);
}
}