복붙노트

[ANGULAR] Angular 4의 HashlocationStrategy 및 쿼리 매개 변수

ANGULAR

Angular 4의 HashlocationStrategy 및 쿼리 매개 변수

해결법


  1. 1.HashlocationStrategy가 이미 기본적으로 사용되므로 실제 브라우저 위치에 도달하기 위해 PathLocateStrategy를 추가로 주입해야합니다.

    HashlocationStrategy가 이미 기본적으로 사용되므로 실제 브라우저 위치에 도달하기 위해 PathLocateStrategy를 추가로 주입해야합니다.

      providers: [
        PathLocationStrategy,
        {provide: LocationStrategy, useClass: HashLocationStrategy},
        ...
      ]
    
    ...
    
    class AppComponent {
      constructor(router: Router, pathLocationStrategy: PathLocationStrategy) {
        const basePath = pathLocationStrategy.getBaseHref();
        const absolutePathWithParams = pathLocationStrategy.path();
    
        if (basePath !== absolutePathWithParams) {
          router.navigateByUrl(absolutePathWithParams);
        }
      }
    }
    

    기본 URL이 있으면 경로에서 추가로 꺼야합니다.

  2. from https://stackoverflow.com/questions/46396572/hashlocationstrategy-and-query-parameters-in-angular-4 by cc-by-sa and MIT license