我想使用我的路由器来检测页面何时刷新单页应用程序 https://en.wikipedia.org/wiki/Single-page_application(角度项目)。
还有其他方法吗?
In the 组件.ts file:
import { Subscription } from 'rxjs';
export let browserRefresh = false;
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnDestroy {
subscription: Subscription;
constructor(private router: Router) {
this.subscription = router.events.subscribe((event) => {
if (event instanceof NavigationStart) {
browserRefresh = !router.navigated;
}
});
}
在您需要的页面中:
import { browserRefresh } from '../app.component';
....
ngOnInit() {
this.browserRefresh = browserRefresh;
console.log('refreshed?:', browserRefresh);
}
请参阅以下位置的工作示例https://stackblitz.com/edit/refreshangular?file=src%2Fapp%2Fpage-a%2Fpage-a.component.ts https://stackblitz.com/edit/refreshangular?file=src%2Fapp%2Fpage-a%2Fpage-a.component.ts
单击页面 A 和页面 B。刷新即可查看差异。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)