Skip to content

Commit cb7f51f

Browse files
refactor(otherwise): Switch otherwise to passthrough (ui-router-core 3.1.0 API)
1 parent a1855ab commit cb7f51f

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/ng2/uiRouterConfig.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,8 @@ export function applyModuleConfig(uiRouter: UIRouter, injector: Injector, option
1414
}
1515

1616
export function applyRootModuleConfig(uiRouter: UIRouter, injector: Injector, config: RootModule) {
17-
if (isDefined(config.deferIntercept)) {
18-
uiRouter.urlRouterProvider.deferIntercept(config.deferIntercept);
19-
}
20-
21-
if (isDefined(config.otherwise)) {
22-
if (isDefined(config.otherwise['state'])) {
23-
uiRouter.urlRouterProvider.otherwise(function() {
24-
let { state, params } = <any> config.otherwise;
25-
uiRouter.stateService.go(state, params, { source: "otherwise" });
26-
return null;
27-
});
28-
} else {
29-
uiRouter.urlRouterProvider.otherwise(<any> config.otherwise);
30-
}
31-
}
17+
isDefined(config.deferIntercept) && uiRouter.urlService.deferIntercept(config.deferIntercept);
18+
isDefined(config.otherwise) && uiRouter.urlService.rules.otherwise(config.otherwise);
3219
}
3320

3421

src/ng2/uiRouterNgModule.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
/** @ng2api @module core */ /** */
2-
import {Ng2StateDeclaration} from "./interface";
3-
import {NgModule, OpaqueToken, ModuleWithProviders, ANALYZE_FOR_ENTRY_COMPONENTS, Provider, Type} from "@angular/core";
4-
import {CommonModule} from "@angular/common";
5-
import {_UIROUTER_DIRECTIVES} from "./directives/directives";
6-
import {UIView} from "./directives/uiView";
7-
import {RawParams} from "ui-router-core";
8-
import {identity} from "ui-router-core";
9-
import {LocationStrategy, HashLocationStrategy, PathLocationStrategy} from "@angular/common";
10-
import {_UIROUTER_INSTANCE_PROVIDERS, _UIROUTER_SERVICE_PROVIDERS} from "./providers";
1+
/** @ng2api @module core */
2+
/** */
3+
import { Ng2StateDeclaration } from "./interface";
4+
import {
5+
NgModule, OpaqueToken, ModuleWithProviders, ANALYZE_FOR_ENTRY_COMPONENTS, Provider, Type
6+
} from "@angular/core";
7+
import { CommonModule, LocationStrategy, HashLocationStrategy, PathLocationStrategy } from "@angular/common";
8+
import { _UIROUTER_DIRECTIVES } from "./directives/directives";
9+
import { UIView } from "./directives/uiView";
10+
import { UrlRuleHandlerFn, TargetState, TargetStateDef } from "ui-router-core";
11+
import { _UIROUTER_INSTANCE_PROVIDERS, _UIROUTER_SERVICE_PROVIDERS } from "./providers";
1112

1213
export function makeRootProviders(module: StatesModule): Provider[] {
1314
return [
@@ -157,7 +158,7 @@ export interface RootModule extends StatesModule {
157158
/**
158159
* Sets [[UrlRouterProvider.otherwise]].
159160
*/
160-
otherwise?: (string | Function | { state: string, params?: RawParams })
161+
otherwise?: (string | UrlRuleHandlerFn | TargetState | TargetStateDef)
161162

162163
/**
163164
* Sets [[UrlRouterProvider.deferIntercept]]

0 commit comments

Comments
 (0)