我读到过关于处理被阻止的更新的文章,但没有运气:
<Provider store={createStoreWithMiddleware(reducers)}>
<Router>
<Route component={App}/>
</Router>
</Provider>和app.js:
class App extends Component {
render() {
return (
<div>
<Switch>
<Route exact path="/" component={Home}/>
{/*<Route exact path="/Blog" render={props => (
<Redirect to={`/Blog/page-${props.match.params.id}`}/>
)}/>*/}
<Redirect exact from="/blog" push to="/blog/page=1"/>
<Route path="/blog/page=:p" component={BlogPage}/>
<Route path="/post/:id" component={BlogPageInfoPage}/>
<Route path="/blog/categories/:id/page=:p" component={FilterCategoryPage}/>
<Route path="/blog/search/:term/page=:p" component={SearchCategoryPage}/>
<Route path="/cart" component={Cart}/>
<Route path="/products" component={Products}/>
<Route path="/product/:id" component={ProductPage}/>
<Route path="/supplier" component={SupplierHomePage}/>
<Route path="/register" component={RegisterPage}/>
<Route path="/*" component={NotFound}/>
</Switch>
<Footer/>
</div>
);
}
}
export default App;我正在点击子组件链接:
<Link to={`/blog/categories/${cat.id}/page=1`}><span
className="fs-11 text-muted float-left"></span>{cat.title}</Link>我知道位置第一次会改变,但第二次不会改变,而且父页面会有特别的withRouter:
function mapStateToProps(state) {
return {posts: state.posts, blogPagination: state.blogPagination};
}
export default withRouter(connect(mapStateToProps, {fetchSpecificCats, fetchBlogCatPagination})(FilterCategory));如果您需要更多代码来了解发生了什么,请告诉我
发布于 2018-05-10 23:36:18
试着改变:
export default connect(mapStateToProps, {fetchSpecificCats, fetchBlogCatPagination})(withRouter(FilterCategory));发布于 2018-05-11 12:42:10
我用componentDidUpdate实现了这一点,它是有效的:
componentDidUpdate(prevProps) {
if (prevProps.location !== this.props.location) {
const {id} = this.props.match.params;
const {p} = this.props.match.params;
this.props.fetchSpecificCats(id, p);
this.props.fetchBlogCatPagination(id, p);
}
}https://stackoverflow.com/questions/50276495
复制相似问题