2016-09-19 13 views
1

example hereでは、このissue commentには、useBeforeUnload関数のhistoryを使用することをお勧めします。ヒストリーユースの代替品は何ですか?リアルータに確認ダイアログを表示するには、事前にダウンロードしてください。

ただし、この機能は廃止されました。 removed without replacement in the current 4.x version

「ミドルウェア」API(つまり、すべての「使用」機能)が削除されたようです。

確認ダイアログを表示するために、これらの「アンロード」前のケースをキャッチするのに良い方法はありますか?

答えて

0

historyのcreateBrowserHistoryのコードを見て、block関数が必要な機能を果たしているように見えます。ドキュメントから:

// Register a simple prompt message that will be shown the 
// user before they navigate away from the current page. 
const unblock = history.block('Are you sure you want to leave this page?') 

// Or use a function that returns the message when it's needed. 
history.block((location, action) => { 
    // The location and action arguments indicate the location 
    // we're transitioning to and how we're getting there. 

    // A common use case is to prevent the user from leaving the 
    // page if there's a form they haven't submitted yet. 
    if (input.value !== '') 
    return 'Are you sure you want to leave this page?' 
}) 

// To stop blocking transitions, call the function returned from block(). 
unblock() 

https://github.com/mjackson/history#blocking-transitions

関連する問題