1+ import { UIRouter } from "../router" ;
2+ /**
3+ * Provides states configuration to UI-Router during application bootstrap.
4+ *
5+ * An instance of this class should be `provide()`d to the application `bootstrap()`.
6+ *
7+ * @example
8+ * ```js
9+ * import {UIROUTER_PROVIDERS, UiView} from "ui-router-ng2";
10+ * import {MyConfig} from "./app/myConfig";
11+ *
12+ * bootstrap(UiView, [
13+ * ...UIROUTER_PROVIDERS,
14+ * provide(UIRouterConfig, { useClass: MyConfig }
15+ * ]);
16+ * ```
17+ *
18+ * The application's initial states should be registered with the [[UIRouter.stateRegistry]].
19+ * Any global configuration (transition hooks, parameter types, etc) should be done here.
20+ *
21+ * @example
22+ * ```js
23+ *
24+ * // myconfig.ts
25+ * import {STATES} from "./states";
26+ * import {registerAuthHook} from "./hooks";
27+ * import {registerSlugType} from "./paramtypes";
28+ *
29+ * export class MyConfig {
30+ * configure(uiRouter: UIRouter) {
31+ * STATES.forEach(state => uiRouter.stateRegistry.register(state));
32+ * registerAuthHook(uiRouter.transitionService);
33+ * registerSlugType(uiRouter.urlMatcherFactory);
34+ * }
35+ * }
36+ *
37+ * // states.ts
38+ * import {FooComponent} from "./foo.component";
39+ * import {BarComponent} from "./bar.component";
40+ * import BAZ_MODULE_STATES from "./baz/states";
41+ *
42+ * export let STATES = [
43+ * { name: 'foo', url: '/url', component: FooComponent},
44+ * { name: 'bar', url: '/bar', component: BarComponent}
45+ * ].concat(BAZ_MODULE_STATES);
46+ *
47+ * // hooks.ts
48+ * export function registerAuthHook(transitionService: TransitionService) {
49+ * let requireAuthentication = ($state, AuthService) {
50+ * if (!AuthService.isAuthenticated()) {
51+ * return $state.target('login');
52+ * }
53+ * }
54+ * transitionService.onBefore({ to: (state) => state.requiresAuth }, requireAuthentication);
55+ * }
56+ *
57+ *
58+ * // paramtypes.ts
59+ * export function registerSlugType(urlMatcherFactory: UrlMatcherFactory) {
60+ * let builtInStringType = urlMatcherFactory.type('string');
61+ * let slugType = Object.assign({}, builtInStringType, { encode: (str) => str, decode: (str) => str });
62+ * urlMatcherFactory.type('slug', slugType);
63+ * }
64+ * ```
65+ *
66+ */
67+ export class UIRouterConfig {
68+ /**
69+ * Configures UI-Router before bootstrap
70+ *
71+ * An app should perform UI-Router configuration here, such as registering the initial set of states,
72+ * parameter types, defining global hooks, etc.
73+ *
74+ * @param uiRouter the uiRouter instance being configured
75+ */
76+ public configure ( uiRouter : UIRouter ) {
77+
78+ }
79+ }
0 commit comments