ui-router-server / ssr-client / seed
Function: seed()
function seed(
router,
payload,
options?
): () => void;Defined in: ssr-client.ts:153
Seeds router with a resolve payload, so the transition it was drawn for adopts the payload's values in place of running their resolve functions.
Call it before the router starts. The boot transition is still a real transition, with every hook it would fire; only the resolves change. When its target state and url parameters are the ones the payload was drawn for, each entering state's resolves in the payload are pre-resolved with the payload's values. Every other resolve runs its function as it would without a payload: a resolve the payload does not carry, a NOWAIT resolve, every resolve of a transition drawn for another state or other parameters, and every resolve when payload is undefined. A transition that redirects is checked against the payload again as its successor.
A value a transporter carried is rebuilt by the transporter of the same name in `transport` before it is adopted. When that transporter is missing, or its decode throws, only that resolve runs its function, and in development seed warns.
The seed disarms itself once a transition succeeds.
Parameters
| Parameter | Type | Description |
|---|---|---|
router | UIRouter | the client router, its states registered |
payload | ResolvePayload | undefined | the payload dehydrate drew, as parsed from the document, or undefined when there is none |
options? | SeedOptions | the transporters that rebuild values beyond plain JSON |
Returns
a function that disarms the seed
() => void
Throws
a TypeError, before any hook is registered, when payload.resolves or a state's entry in it is null or missing
Example
import type { UIRouter } from '@uirouter/core';
import type { ResolvePayload } from 'ui-router-server/ssr';
import { seed } from 'ui-router-server/ssr/client';
declare const router: UIRouter;
declare const payload: ResolvePayload | undefined;
seed(router, payload);
router.urlService.listen();
router.urlService.sync();