|
10 | 10 | - [`urlRouterProvider`](#urlrouterprovider-urlrouterprovider)
|
11 | 11 | - [`viewService`](#viewservice-viewservice)
|
12 | 12 | - [`start()`](#start-void)
|
13 |
| - - [`html5mode()`](#html5modemode-boolean-void) |
| 13 | + - [`plugin()`](#plugin-uirouterplugin) |
| 14 | + - [`html5mode()`](#html5modemode-boolean-void) - *deprecated* |
14 | 15 |
|
15 | 16 | - [State Declaration](#state-declaration)
|
16 | 17 | - [`abstract`](#abstract-boolean)
|
|
28 | 29 | - [`views`](#views-object)
|
29 | 30 |
|
30 | 31 | - [Components](#components)
|
| 32 | + - [`<UIRouter>`](#uirouter) |
31 | 33 | - [`<UIView>`](#uiview)
|
32 | 34 | - [`<UISref>`](#uisref)
|
33 | 35 | - [`<UISrefActive>`](#uisrefactive)
|
|
36 | 38 |
|
37 | 39 | - [Transitions](#transitions)
|
38 | 40 |
|
| 41 | +- [Plugins](#plugins) |
| 42 | + - [`pushStateLocationPlugin`](#pushStateLocationPlugin) |
| 43 | + - [`hashLocationPlugin`](#hashLocationPlugin) |
| 44 | + - [`memoryLocationPlugin`](#memoryLocationPlugin) |
| 45 | + |
39 | 46 | - [Utilities](#utilities)
|
40 | 47 | - [`trace`](#trace)
|
41 | 48 |
|
@@ -108,14 +115,16 @@ Take a look at the [ViewService Class](https://ui-router.github.io/docs/latest/c
|
108 | 115 | #### `start()`: void
|
109 | 116 | Starts the router. It tells the router to listen for state changes and to sync the url accordingly.
|
110 | 117 |
|
| 118 | +#### `plugin()`: UIRouterPlugin |
| 119 | +Register a plugin in the router instance, the plugin is returned by the function. |
| 120 | + |
111 | 121 | #### `html5mode(mode: boolean)`: void
|
112 | 122 |
|
| 123 | +**Deprecated in 0.4.0!** |
| 124 | + |
113 | 125 | By default UI-Router works with a `HashLocation` history implementation.
|
114 | 126 | If `mode` is true, the HTML5 `PushStateLocation` will be used instead.
|
115 | 127 |
|
116 |
| -> WARNING, html5mode() is a temporary API and will likely change in the future. |
117 |
| -> Future versions of UI-Router React will provide a way to specify custom history implementation. |
118 |
| -
|
119 | 128 | ## State Declaration
|
120 | 129 | A state declaration object is used to register a new state. It is registered via the `stateRegistry`.
|
121 | 130 |
|
@@ -400,12 +409,94 @@ views: {
|
400 | 409 |
|
401 | 410 | ## Components
|
402 | 411 |
|
| 412 | +### `<UIRouter>` |
| 413 | +
|
| 414 | +Main router component that handles router instance and initialization. |
| 415 | +
|
| 416 | +```jsx |
| 417 | +render( |
| 418 | + <UIRouter plugins={[•••]} states={[•••]}> |
| 419 | + <UIView /> |
| 420 | + </UIRouter>, |
| 421 | + document.getElementById('root') |
| 422 | +); |
| 423 | +``` |
| 424 | +
|
| 425 | +#### Props |
| 426 | +
|
| 427 | +##### `children`: element |
| 428 | +
|
| 429 | +You may define a single child element. Descendants of this component will have access to the router instance via React context. |
| 430 | +
|
| 431 | +##### `plugins`: array |
| 432 | +
|
| 433 | +Plugins to apply to the router instance. By default, the component applies the `servicesPlugin` which is in charge of handling the DI mechanism as well as the promises implementation. |
| 434 | +
|
| 435 | +In order for the router to work, you need to specify a location plugin. |
| 436 | +The library by default provides three location implementation plugins: `hash`, `pushState` and `memory`. |
| 437 | +
|
| 438 | +There are other plugins that extend the router base functionalities and you can also write your own plugin. |
| 439 | +
|
| 440 | +##### `states`: array |
| 441 | +
|
| 442 | +You may provide an array of state definition that are registered right after the router is initialized. |
| 443 | +
|
| 444 | +##### `config`: function |
| 445 | +
|
| 446 | +THe config prop accepts a function that will be called with the newly router instance as argument. |
| 447 | +You can use this function to configure the router: |
| 448 | +
|
| 449 | +```jsx |
| 450 | +const configRouter = router => { |
| 451 | + router.urlRouterProvider.otherwise("/home"); |
| 452 | +} |
| 453 | + |
| 454 | +render( |
| 455 | + <UIRouter plugins={[•••]} states={[•••]} config={configRouter}> |
| 456 | + <UIView /> |
| 457 | + </UIRouter>, |
| 458 | + document.getElementById('root') |
| 459 | +); |
| 460 | +``` |
| 461 | +
|
| 462 | +##### `router`: UIRouterReact |
| 463 | +
|
| 464 | +Since UI-Router is framework agnostic, you can set-up the router manually in "vanilla" ui-router, and pass the instance to the component. |
| 465 | +This way the component will skip the previous props and just use the provided instance. |
| 466 | +
|
| 467 | +```jsx |
| 468 | +import {UIRouterReact, UIRouter, UIView, servicesPlugin, pushStateLocationPlugin} from 'ui-router-react'; |
| 469 | + |
| 470 | +const someState = { name: 'some', url: '', component: SomeComponent }; |
| 471 | +// create instance |
| 472 | +const router = new UIRouterReact(); |
| 473 | +// activate plugins |
| 474 | +router.plugin(servicesPlugin); |
| 475 | +router.plugin(pushStateLocationPlugin); |
| 476 | +// register states |
| 477 | +router.stateRegistry.register(someState); |
| 478 | +// start the router |
| 479 | +router.start(); |
| 480 | + |
| 481 | +ReactDOM.render( |
| 482 | + <UIRouter router={router}> |
| 483 | + <UIView /> |
| 484 | + </UIRouter>, |
| 485 | + document.getElementById("root") |
| 486 | +); |
| 487 | +``` |
| 488 | +
|
| 489 | +> NB: since you are manually bootstrapping the router, you must register the `servicesPlugin` as well as the location plugin of your choice (in this example the `pushStateLocationPlugin`). |
| 490 | +
|
403 | 491 | ### `<UIView>`
|
404 |
| -The view component renders your state components when a state is active. |
| 492 | +
|
| 493 | +The view component renders your state components when a state is active. It must be a descendant of `<UIRouter>` component in order to work. |
405 | 494 |
|
406 | 495 | ```jsx
|
407 | 496 | render(
|
408 |
| - <UIView/> |
| 497 | + <UIRouter {•••}> |
| 498 | + <UIView/> |
| 499 | + </UIRouter>, |
409 | 500 | document.getElementById('root')
|
410 | 501 | );
|
411 | 502 | ```
|
@@ -531,6 +622,25 @@ The transitions are always inject in the state components via the `transition` p
|
531 | 622 |
|
532 | 623 | Take a look at the [Transition Class](https://ui-router.github.io/docs/latest/classes/transition.transition-1.html) for more info.
|
533 | 624 |
|
| 625 | +## Plugins |
| 626 | +
|
| 627 | +Plugins are a handy way to extend UI-Router functionalities. The router internally uses a DI mechanism as well as a Promise implementation. |
| 628 | +Both are implemented as the `servicesPlugin`. |
| 629 | +
|
| 630 | +Location implementation are also implemented as plugins: |
| 631 | +
|
| 632 | +### `pushStateLocationPlugin` |
| 633 | +
|
| 634 | +Location strategy via html5 `pushState` API. |
| 635 | +
|
| 636 | +### `hashLocationPlugin` |
| 637 | +
|
| 638 | +Location strategy via url hash portion (i.e. `myurl.com/#/home`). |
| 639 | +
|
| 640 | +### `memoryLocationPlugin` |
| 641 | +
|
| 642 | +Location strategy via in-memory object, useful for environments where a location is not present (server-side code for SSR). |
| 643 | +
|
534 | 644 | ## Utilities
|
535 | 645 |
|
536 | 646 | ### `trace`
|
|
0 commit comments