3
我想我的反应路由器有一些问题。我怎样才能防止反应路由器重新渲染先前呈现的页面?如何防止反应路由器重新呈现以前呈现的页面?
我有路由器这样的代码:
class App extends React.Component {
render() {
return (
<div>
<NavBar/>
{this.props.children}
</div>
);
}
}
ReactDOM.render(
(
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRoute component={Gateway} />
<Route path="home" component={Gateway} />
<Route path="categories" component={Categories} />
</Route>
</Router>
), document.getElementById('my-app')
);
当我第一次访问该页面,它击中指数,Gateway组件得到了呈现。然后我点击“类别”链接,类别组件得到渲染。然后,当我再次点击“home”链接时,组件网关被重新渲染。它的状态得到了RESET。这真是令人沮丧,因为我无法弄清楚为什么它的状态得到重置。
有没有解决方案?
如果您没有使用Redux等任何状态管理,那么您必须查找正确的方式来使用React共享路由之间的状态。看看这个帖子中的答案:http://stackoverflow.com/questions/41108701/react-router-share-state-between-routes-without-redux或谷歌的东西,如“反应路由器之间的路由器共享状态” – Jayce444