以前在react SPA 项目中,我会通过react生命周期监听参数的变化,然后重新请求数据,但是服务端渲染没有此生命周期,如何监听?
原来的代码:
componentWillReceiveProps(nextProps) {
const { location } = this.props;
if (nextProps.location.pathname !== location.pathname) {
this.setMetas();
}
}
这个
componentWillReceiveProps
生命周期都要废弃了。用
redux
的subscription
监听就好了。