해당 컴포넌트에 roure event를 subscribe 한 후 destroy에서 해당 이벤트를 unsubscribe 한다.
this.router.navigated = false;
this.router.onSameUrlNavigation = "reload"; // 현재URL로 이동시 이벤트를 발생 시킨다.
this.router.navigate([MAIN_URI]);
=================== component ============================================
constructor 구문에서
this.navigationSubscription = this.router.events.subscribe((e: any) => {
// route의 onSameUrlNavigation을 RELOAD로 설정할경우 동일한 라우트로 요청이 되더라도
// 네비게이션 이벤트가 발생한다.
if (e instanceof NavigationEnd) {
this.ngOnInit();
}
});
ngOnInit 구문에서 동일 url 이동시 이벤트를 다시 ignore 시킨다.
this.router.onSameUrlNavigation = "ignore";
==========================================================
destroy
ngOnDestroy() {
//this.eventManager.destroy(this.eventSubscriber);
if(this.interval) clearInterval(this.interval);
if(this.navigationSubscription) this.navigationSubscription.unsubscribe();
}
덧글