2017-11-17 11 views
0

대신 마지막 상태의 최종 모듈을 얻을 수있는 방법은 예를 들어, 존재 경우 페이지 B에 대한 페이지 (A)로부터 어떤 하나의 루트 페이지 내부 B 일부 진행에서 일부 선택적 매개 변수를 추가합니다. 뒤로 버튼을 클릭 할 때 사용자는 선택적 매개 변수가없는 페이지 B가있는 경로로 직접 가지 않고 페이지 A로 직접 돌아갈 수 있어야합니다.행 위로 마지막 페이지 (모듈) 대신 마지막 상태 타이프에서

답변

1

이 코드는 방문한 마지막 페이지의 모듈을 얻는 데 도움이되었습니다. Pls 시도해보십시오.

import { Router , NavigationEnd} from '@angular/router'; 

    export class myComponent { 
    private previousUrl: string; 

    constructor(private router: Router){ 

     router.events 
     .filter(event => event instanceof NavigationEnd) 
     .subscribe(e => { 
      let path = this.previousUrl; 
      if(path !="" && path!=undefined){ 
       let res = path.split("/"); 
       console.log(res[1]); /* here in res[1] you will get the last clicked page module url. Now you can route to last module using this res[1] value */ 
      } 
     this.previousUrl = e.url; 

     }); 
    } 
} 

희망이 있습니다.

+0

이것은 실제로 대답이되어야하는 것입니다. – Heshan