|
1 | 1 | /** |
2 | 2 | * # UI-Router for Angular 2 |
3 | 3 | * |
4 | | - * For the quick start repository, please see http://github.com/ui-router/quickstart-ng2 |
5 | | - * |
| 4 | + * - [ui-router-ng2 home page](https://ui-router.github.io/ng2) |
| 5 | + * - [tutorials](https://ui-router.github.io/tutorial/ng2/helloworld) |
| 6 | + * - [quick start repository](http://github.com/ui-router/quickstart-ng2) |
| 7 | + * |
6 | 8 | * Getting started: |
7 | 9 | * |
8 | 10 | * - Use npm. Add a dependency on latest `ui-router-ng2` |
|
12 | 14 | * import {StateRegistry} from "ui-router-ng2"; |
13 | 15 | * ``` |
14 | 16 | * |
15 | | - * - When defining a component, add the [[UIROUTER_DIRECTIVES]] to `directives:` array. |
16 | | - * - Either bootstrap a [[UIView]] component, or add a `<ui-view></ui-view>` viewport to your root component. |
17 | | - * - Create application states (as defined by [[Ng2StateDeclaration]]) which will fill in the viewports. |
18 | | - * - Create a [[UIRouterConfig]], and register your states in the [[UIRouterConfig.configure]] function. |
| 17 | + * - Create application states (as defined by [[Ng2StateDeclaration]]). |
| 18 | + * |
| 19 | + * ```js |
| 20 | + * export let state1 = { |
| 21 | + * name: 'state1', |
| 22 | + * component: State1Component, |
| 23 | + * url: '/one' |
| 24 | + * } |
| 25 | + * |
| 26 | + * export let state2 = { |
| 27 | + * name: 'state2', |
| 28 | + * component: State2Component, |
| 29 | + * url: '/two' |
| 30 | + * } |
| 31 | + * ``` |
| 32 | + * |
| 33 | + * - Create application feature modules using [[UIRouterModule]] |
| 34 | + * |
| 35 | + * ```js |
| 36 | + * @ UIRouterModule({ |
| 37 | + * imports: [ CommonModule ], |
| 38 | + * states: [ state1, state2 ] |
| 39 | + * }) |
| 40 | + * export class MyFeatureModule {} |
| 41 | + * ``` |
| 42 | + * |
| 43 | + * - Optionally create a [[UIRouterConfig]] to perform any pre-bootstrap configuration. |
19 | 44 | * |
20 | 45 | * ```js |
21 | 46 | * import {UIRouter} from "ui-router-ng2"; |
22 | | - * import {INITIAL_STATES} from "./app.states"; |
| 47 | + * |
23 | 48 | * @ Injectable() |
24 | 49 | * export class MyUIRouterConfig { |
| 50 | + * constructor() {} // Constructor is injectable |
25 | 51 | * configure(uiRouter: UIRouter) { |
26 | | - * INITIAL_STATES.forEach(function(state) { |
27 | | - * uiRouter.stateRegistry.register(state)); |
28 | | - * }); |
| 52 | + * uiRouter.urlRouterProvider.otherwise(() => uiRouter.stateService.target('home')); |
29 | 53 | * } |
30 | 54 | * } |
31 | 55 | * ``` |
32 | 56 | * |
33 | | - * - When bootstrapping: include the [[UIROUTER_PROVIDERS]] and define a provider for your [[UIRouterConfig]] |
| 57 | + * - When bootstrapping the root module: use the [[provideUIRouter]] function: |
| 58 | + * - Either bootstrap a [[UIView]] component, or add a `<ui-view></ui-view>` viewport to your root component. |
34 | 59 | * |
35 | 60 | * ```js |
36 | | - * import {provide} from "@angular/core"; |
37 | | - * import {bootstrap} from 'angular2/platform/browser'; |
38 | | - * import {UIRouterConfig, UIView, UIROUTER_PROVIDERS} from "ui-router-ng2"; |
| 61 | + * import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; |
| 62 | + * import {UIRouterModule, provideUIRouter, UIView} from "ui-router-ng2"; |
39 | 63 | * import {MyUIRouterConfig} from "./router.config"; |
40 | 64 | * |
41 | | - * bootstrap(UIView, [ |
42 | | - * ...UIROUTER_PROVIDERS, |
43 | | - * provide(UIRouterConfig, { useClass: MyUIRouterConfig }) |
44 | | - * ]); |
| 65 | + * @ UIRouterModule({ |
| 66 | + * import: [ FeatureModule, BrowserModule ], |
| 67 | + * providers: [ provideUIRouter({ configClass: MyUIRouterConfig }) ], |
| 68 | + * states: [ homeState ], |
| 69 | + * bootstrap: [ UIView ] |
| 70 | + * }) |
| 71 | + * class RootAppModule {} |
| 72 | + * |
| 73 | + * platformBrowserDynamic().bootstrapModule(RootAppModule); |
45 | 74 | * ``` |
46 | 75 | * |
47 | 76 | * @preferred @module ng2 |
|
0 commit comments