2017-12-18 9 views
0

URLが変更されたときにReduxForm統合コンポーネントを再レンダリングしようとしていますが、コンポーネントは同じままです。Reduxフォーム - 同じコンポーネントからURLが変更された場合に再レンダリングする方法?

私はcomponentDidUpdateため

componentWillReceiveProps(nextProps){ 
if (this.props.history.location.pathname 
    !== nextProps.history.location.pathname){ 
    console.log('here, new route but same component!'); 
} 

だけでなく、同じことを試してみましたが、nextPropsthis.propsは同じです! ReduxFormまたはconnectは、URLが変更された場合でも、登録方法について全く混乱し、私を残して、コンポーネントのthisオブジェクトを変更している -

componentDidUpdate(prevProps) { 
    console.log(this.props.location) 
    console.log(prevProps.location); 
    // These two are the same! 
    } 

また、私はnextProps.paramsにアクセスすることはできません。

私は「キャッシュ」それまでの状態にある変数に元this.props.history.location.pathnameを格納してみwindow.location.reload()

答えて

0

を使用しないでしょう。私は、時間componentWillRecievePropsで

this.propsと呼ばれていると思うことnextProps

//このようなものと同じである....

componentDidMount(){ 
this.setState({cachedURL: this.props.history.location.pathname}) 
} 

componentWillRecieveProps(nextProps){ 
if (this.state.cachedURL 
    !== nextProps.history.location.pathname){ 
    console.log('here, new route but same component!'); 
} 
+0

問題はnextPropsはまだ時に変更されていないということですURLが変更されているため、それ自体はまだチェックしています –

関連する問題