Skip to content

Commit 0ee00c3

Browse files
doc(lazyLoad): add more details for StateDefinition.lazyLoad
1 parent 9013070 commit 0ee00c3

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/state/interface.ts

+19-22
Original file line numberDiff line numberDiff line change
@@ -521,26 +521,28 @@ export interface StateDeclaration {
521521
onExit?: TransitionStateHookFn;
522522

523523
/**
524-
* A function which lazy loads the state (and child states)
524+
* A function which lazy loads the state definition (and child state definitions)
525525
*
526526
* A state which has a `lazyLoad` function is treated as a **temporary
527527
* placeholder** for a state definition that will be lazy loaded some time
528528
* in the future.
529529
* These temporary placeholder states are called "**Future States**".
530530
*
531531
*
532-
* ### Future State placeholders
533-
*
534532
* #### `lazyLoad`:
535533
*
536-
* A future state's `lazyLoad` function should return a Promise for an array of
537-
* lazy loaded [[StateDeclaration]] objects.
534+
* A future state's `lazyLoad` function should return a Promise to lazy load the
535+
* code for one or more lazy loaded [[StateDeclaration]] objects.
536+
*
537+
* If the promise resolves to an object with a `states: []` array,
538+
* the lazy loaded states will be registered with the [[StateRegistry]].
539+
* Generally, of the lazy loaded states should have the same name as the future state;
540+
* then it will **replace the future state placeholder** in the registry.
538541
*
539-
* The lazy loaded states are registered with the [[StateRegistry]].
540-
* One of the lazy loaded states must have the same name as the future state;
541-
* it will **replace the future state placeholder** in the registry.
542+
* In any case, when the promise successfully resolves, the placeholder Future State will be deregistered.
542543
*
543544
* #### `url`
545+
*
544546
* A future state's `url` property acts as a wildcard.
545547
*
546548
* UI-Router matches all paths that begin with the `url`.
@@ -553,22 +555,10 @@ export interface StateDeclaration {
553555
* It matches any state name that starts with the `name`.
554556
* UI-Router effectively matches the future state using a `.**` [[Glob]] appended to the `name`.
555557
*
556-
* ---
557-
*
558-
* Future state placeholders should only define `lazyLoad`, `name`, and `url`.
559-
* Any additional properties should only be defined on the state that will eventually be lazy loaded.
560-
*
561558
* @example
562559
* #### states.js
563560
* ```js
564561
*
565-
* // The parent state is not lazy loaded
566-
* {
567-
* name: 'parent',
568-
* url: '/parent',
569-
* component: ParentComponent
570-
* }
571-
*
572562
* // This child state is a lazy loaded future state
573563
* // The `lazyLoad` function loads the final state definition
574564
* {
@@ -598,11 +588,18 @@ export interface StateDeclaration {
598588
* }
599589
* };
600590
*
601-
* // The future state's lazyLoad imports this array of states
602-
* export default [ childState ];
591+
* // This array of states will be registered by the lazyLoad hook
592+
* let result = {
593+
* states: [ childState ]
594+
* };
595+
*
596+
* export default result;
603597
* ```
604598
*
605599
* @param transition the [[Transition]] that is activating the future state
600+
* @return a Promise to load the states.
601+
* Optionally, if the promise resolves to a [[LazyLoadResult]],
602+
* the states will be registered with the [[StateRegistry]].
606603
*/
607604
lazyLoad?: (transition: Transition) => Promise<LazyLoadResult>;
608605

0 commit comments

Comments
 (0)