2016-03-24 10 views
1

私はちょうど何が起こっているか分からない、これは期待された動作かどうかです。POPの履歴はlocation.stateの機能をクリアしますか?

まず、私は

/path1

const state = { 
    action:() => {}, 
    other: 'other' 
    } 
    this.props.history.replaceState(state, '/path2') 

が、私はこの時に、いくつかのルート /path2

this.props.history.replaceState(this.props.location.state, '/path3') 

に周りの様子をお送りします位置の状態で周りの機能をどのように送信しますポイント、私は場所の状態を記録する場合、actionまだそこに

console.log(this.props.location.state) // print { action: fn(), other: 'other' } 

しかし、私は、ブラウザ上でgo backを実行すると、今の私は、ルートで午前/path1

console.log(this.props.location.state) // print { other: 'other' } 

君たちはfunctionが場所の状態から削除されていることがわかります。 私の質問はなぜこれが起こっているのですか?この背後に何らかの理由がありますか?

ブラウザに戻って実行すると、私はたとえば、オブジェクト に

const state = { 
    action: { moreAction:() => {} }, 
    other: 'other' 
    } 
    this.props.history.replaceState(state, '/path2') 

functionを入れた場合でも、場所の状態がまだ

console.log(this.props.location.state) // print { action: {}, other: 'other' } 

ようなことは、事前に

答えて

0

をありがとうロケーションステートの内容はJSONシリアライザブルでなければなりません。そこに関数を置くことはできません。

+0

私のやっていることは、ロケーションステートの目的ではないことを知っていますが、なんらかの理由で特定のケースで行う必要があります。実際に私は関数を渡すことができますが、残念なことに、戻ってきたら、それはクリアされました。 – Krit

関連する問題