<HashRouter>
<main>
<Switch>
<Route exact path="/" component={IndexPage} />
<Route path="/login" component={Login} />
<Route path="/album" component={Album} />
</Switch>
</main>
</HashRouter>
如题,定义了一个名为album的route,
然后在此路由的component的componentDidMount里,
获取到this.props.location.search,即"?id=1",通过异步获取数据然后更新store,触发此组件的re-render,
这个组件里面有个链接为"/album?id=2"的Link,由于只改变了查询字段,没有触及pathname的更新,所以此链接能点,history也会更新,componentDidUpdate也能看到props.location.search改变,但是store并不更新,所以组件也不会re-render...
所以我该在什么地方更新store呢?
可以使用componentWillReceiveProps重新渲染,这个钩子函数会在组件传入的 props 发生变化时调用。