-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UIRouterConfig): Define UIRouterConfig class for router bootstrap
- Loading branch information
1 parent
ff54d61
commit c16b9e6
Showing
4 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {UIRouter} from "../router"; | ||
/** | ||
* Provides states configuration to UI-Router during application bootstrap. | ||
* | ||
* An instance of this class should be `provide()`d to the application `bootstrap()`. | ||
* | ||
* @example | ||
* ```js | ||
* import {UIROUTER_PROVIDERS, UiView} from "ui-router-ng2"; | ||
* import {MyConfig} from "./app/myConfig"; | ||
* | ||
* bootstrap(UiView, [ | ||
* ...UIROUTER_PROVIDERS, | ||
* provide(UIRouterConfig, { useClass: MyConfig } | ||
* ]); | ||
* ``` | ||
* | ||
* The application's initial states should be registered with the [[UIRouter.stateRegistry]]. | ||
* Any global configuration (transition hooks, parameter types, etc) should be done here. | ||
* | ||
* @example | ||
* ```js | ||
* | ||
* // myconfig.ts | ||
* import {STATES} from "./states"; | ||
* import {registerAuthHook} from "./hooks"; | ||
* import {registerSlugType} from "./paramtypes"; | ||
* | ||
* export class MyConfig { | ||
* configure(uiRouter: UIRouter) { | ||
* STATES.forEach(state => uiRouter.stateRegistry.register(state)); | ||
* registerAuthHook(uiRouter.transitionService); | ||
* registerSlugType(uiRouter.urlMatcherFactory); | ||
* } | ||
* } | ||
* | ||
* // states.ts | ||
* import {FooComponent} from "./foo.component"; | ||
* import {BarComponent} from "./bar.component"; | ||
* import BAZ_MODULE_STATES from "./baz/states"; | ||
* | ||
* export let STATES = [ | ||
* { name: 'foo', url: '/url', component: FooComponent}, | ||
* { name: 'bar', url: '/bar', component: BarComponent} | ||
* ].concat(BAZ_MODULE_STATES); | ||
* | ||
* // hooks.ts | ||
* export function registerAuthHook(transitionService: TransitionService) { | ||
* let requireAuthentication = ($state, AuthService) { | ||
* if (!AuthService.isAuthenticated()) { | ||
* return $state.target('login'); | ||
* } | ||
* } | ||
* transitionService.onBefore({ to: (state) => state.requiresAuth }, requireAuthentication); | ||
* } | ||
* | ||
* | ||
* // paramtypes.ts | ||
* export function registerSlugType(urlMatcherFactory: UrlMatcherFactory) { | ||
* let builtInStringType = urlMatcherFactory.type('string'); | ||
* let slugType = Object.assign({}, builtInStringType, { encode: (str) => str, decode: (str) => str }); | ||
* urlMatcherFactory.type('slug', slugType); | ||
* } | ||
* ``` | ||
* | ||
*/ | ||
export class UIRouterConfig { | ||
/** | ||
* Configures UI-Router before bootstrap | ||
* | ||
* An app should perform UI-Router configuration here, such as registering the initial set of states, | ||
* parameter types, defining global hooks, etc. | ||
* | ||
* @param uiRouter the uiRouter instance being configured | ||
*/ | ||
public configure(uiRouter: UIRouter) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters