Angular 2 : routing without changing URL

后端 未结 3 724
悲哀的现实
悲哀的现实 2020-11-27 12:40

How can i route in an Angular 2 app without changing the URL? (this is because the app is located under one of several tabs on a page of a Django app, where it\'s suitable t

3条回答
  •  爱一瞬间的悲伤
    2020-11-27 13:13

    Update

    router.navigateByUrl("/team/33/user/11", { skipLocationChange: true });
    
    click me
    

    Update

    There is a PR to support this directly https://github.com/angular/angular/pull/9608

    Related issues

    • https://github.com/angular/angular/issues/9579
    • https://github.com/angular/angular/issues/9949

    Original

    You can implement a custom PlatformLocation similar to BrowserPlatformLocation but instead of calling ot history.pushState(), history.replaceState(), history.back(), and history.forward() maintain the changes in a local array.

    You can then make Angular use your custom implementation by providing it like

    bootstrap(AppComponent, 
        [provide(PlatformLocation, {useClass: MyPlatformLocation})]);
    

提交回复
热议问题