Aug 8, 2017 · 1 min read
Great article Victor. Thank you.
A tip for those not using html5 mode for routing — you need to be aware that the default prefix in AngularJS v1.6+ is “#!”, but is just “#” (hash) in Angular.
This can cause an infinite loop as each router’s “otherwise” rule kicks in trying to apply their own prefix.
The solution is to set the “APP_BASE_HREF” injectable in Angular to “!”, like so:
import { APP_BASE_HREF } from '@angular/common';@NgModule({
/* ... */
providers: [{provide: APP_BASE_HREF, useValue: '!'}]
})
export class AppModule {/* ... */}
Or to set $locationProvider.hashPrefix('') in your AngularJS application.
EDIT: Also exclude setUpLocationSync(upgrade)when using hashMode.
References:
https://github.com/angular/angular/issues/4155
https://angular.io/api/common/APP_BASE_HREF
https://docs.angularjs.org/api/ng/provider/$locationProvider#hashPrefix
