base href is case sensitive in Angular 2

后端 未结 4 939
囚心锁ツ
囚心锁ツ 2021-01-20 20:43

I have set the base ref like this for an Angular 2 app


If I go to localhost/MyApp everything works correctly.

4条回答
  •  误落风尘
    2021-01-20 21:29

    I added typed base href as a route in router config with redirectTo property set to default route of the app, which is in my case is 'login', so any combination of base href will work. This is more sort of a hack.

    I wrote that code in the app.component.ts file.

    ngOnInit() {
       var baseHref  = window.location.pathname.split('/')[1];
       if(baseHref != "" && baseHref != "login")
          this.router.config.Add({path:baseHref,redirectTo:'/login',pathMatch:'full'});
    }
    

    Note:- As suggested by other answers, LowerCaseUrlSerializer didn't work for me as it requires all routes specified in my app to be in lower case only.

提交回复
热议问题