ページがユーザーによってリロードされたかどうかを知るために、このコードがありますが、残念ながら非推奨です。angularにこのアプローチがあるかどうか知りたいです。
if (performance.navigation.type === 1) {
console.log('is refreshed')
}
if (performance.navigation.type === 0) {
console.log('the user is arrived')
}
ページがユーザーによってリロードされたかどうかを知るために、このコードがありますが、残念ながら非推奨です。angularにこのアプローチがあるかどうか知りたいです。
if (performance.navigation.type === 1) {
console.log('is refreshed')
}
if (performance.navigation.type === 0) {
console.log('the user is arrived')
}
Angular に固有のものではありませんが、この API はPerformanceNavigationTimingに置き換えられました。この API にもtype
プロパティがありますが、数値コードではなく文字列を返します。
ただし、Chrome は iframe に対してこれを公開しないことに気付きました。これは常に出力されます"navigate"
。
次のスニペットは Chrome では機能しません。代わりにこの plkrを外部ビューで試してください。
const entries = performance.getEntriesByType("navigation");
console.log( entries.map( nav => nav.type ) );
rel.onclick = e => location.reload();
<button type="button" id="rel">reload</button>
<a href="404">go to 404 (come back with your browser's back button)</a>