I have set the base ref like this for an Angular 2 app
If I go to localhost/MyApp everything works correctly.
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.