Angular 2 router no base href set

前端 未结 8 914
半阙折子戏
半阙折子戏 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 16:01

    Check your index.html. If you have accidentally removed the following part, include it and it will be fine

    <base href="/">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="image/x-icon" href="favicon.ico">
    
    0 讨论(0)
  • 2020-11-22 16:03

    I had faced similar issue with Angular4 and Jasmine unit tests; below given solution worked for me

    Add below import statement

    import { APP_BASE_HREF } from '@angular/common';
    

    Add below statement for TestBed configuration:

    TestBed.configureTestingModule({
        providers: [
            { provide: APP_BASE_HREF, useValue : '/' }
        ]
    })
    
    0 讨论(0)
提交回复
热议问题