In UI-Router's RootModule.otherwise we can specify where to redirect the user if the user is opening a URL that the application doesn't recognize. I have been using the simple format, just a string specifying the target state's name:
@NgModule({ imports: [UIRouterModule.forRoot({ states: [ { name: "home", url: "/home", component: HomeComponent } ], otherwise: "/home" })], exports: [UIRouterModule], providers: [] }) export class AppRoutingModule { } But now I need to get data by calling a service to determine which target state I should redirect the user. I tried the function format of the otherwise hoping to be able to get access to my service through the injector:
otherwise: (matchValue, url: UrlParts, router: UIRouter) => { // this didn't work, router.globals.transition is not available const userPrefSvc = router.globals.transition.injector().get(UserPreferenceService); } But it didn't work, I can't find a way to get hold of the injector.
Is it possible to access services from the otherwise function?