我有一个组件,我需要检测用户是否在他的浏览器中按下了按钮以导航回来.
目前我正在订阅路由器事件.
constructor(private router: Router, private activatedRoute: ActivatedRoute) {
this.routerSubscription = router.events
.subscribe(event => {
// if (event.navigatesBack()) ...
});
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用,window.onpopstate但在使用Angular2时感觉就像是黑客.