Angular 2 router no base href set

前端 未结 8 979
半阙折子戏
半阙折子戏 2020-11-22 15:19

I am getting an error and can\'t find why. Here is the error:

EXCEPTION: Error during instantiation of LocationStrategy! (RouterOutlet -> Router -> Loc         


        
8条回答
  •  盖世英雄少女心
    2020-11-22 15:58

    You can also use hash-based navigation by including the following in app.module.ts

    import { LocationStrategy, HashLocationStrategy } from '@angular/common';
    

    and by adding the following to the @NgModule({ ... })

    @NgModule({
      ...
      providers:    [
          ProductService, {
              provide: LocationStrategy, useClass: HashLocationStrategy
          }
      ],
      ...
    })
    

    “HashLocationStrategy—A hash sign (#) is added to the URL, and the URL segment after the hash uniquely identifies the route to be used as a web page fragment. This strategy works with all browsers, including the old ones.”

    Excerpt From: Yakov Fain Anton Moiseev. “Angular 2 Development with TypeScript.”

提交回复
热议问题