angular 中 performance.navigation.type 的替代品是什么?

What is the replacement for performance.navigation.type in angular?

我有这段代码是为了知道页面是否被用户重新加载,不幸的是已被弃用。我想知道angular有没有这个方法

if (performance.navigation.type === 1) {
   console.log('is refreshed')
}

if (performance.navigation.type === 0) {
   console.log('the user is arrived')
}  

不特定于Angular,但是这个API已经被PerformanceNavigationTiming one, which also has a type取代属性,但是其中returns是一个字符串而不是一个数字代码。

但是我刚刚注意到 Chrome 不会为 iframe 公开这个,它总是输出 "navigate".

The following snippet won't work in Chrome, please try this plnkr instead, in external view.

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>

performance.navigation 已弃用。要获取导航类型,您可以使用 getEntriesByType

例子

console.log(performance.getEntriesByType("navigation")[0].type)

type值可以是

enum NavigationType {
    "navigate",
    "reload",
    "back_forward",
    "prerender"
};

查看更多:https://w3c.github.io/navigation-timing/#sec-performance-navigation-types

我想补充一点 运行:

performance.getEntriesByType("navigation");

returns Safari 中的空数组