Routing and navigation in Angular 2

前端 未结 6 1480
误落风尘
误落风尘 2020-12-06 17:45

I am going through the tutorials for Angular 2 and have been able to get a simple application up and running. Now, I am moving on to the routing and navigation part found h

6条回答
  •  时光说笑
    2020-12-06 18:26

    For this issue, you need to use PathLocationStrategy or HashLocationStrategy for your application. It's available in the 'angular2/router'.

    Example for using HashLocationStrategy:

    boot.ts

    bootstrap(AppCmp, [
           ROUTER_PROVIDERS,
           provide(LocationStrategy, {useClass: HashLocationStrategy})
       ]);
    

    and in your main component,

    class AppCmp {
              constructor(location: Location) {
              location.go(location.path());
           }
    

    The location.path() dynamically gives the path for the page to be loaded.

提交回复
热议问题