From a23bf99f8055ef6f6862a2f17e2de32c9b5342a6 Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Wed, 22 Jan 2025 15:37:52 -0600 Subject: [PATCH 1/2] gen api docs --- docs/api/compositions/useLink.md | 4 +- docs/api/functions/createExternalRoute.md | 6 +- docs/api/functions/createRoute.md | 169 ++---------------- docs/api/functions/createRouter.md | 4 +- docs/api/hooks/onAfterRouteEnter.md | 20 --- docs/api/index.md | 13 +- docs/api/type-guards/isRoute.md | 8 +- docs/api/typedoc-sidebar.json | 52 +++++- docs/api/types/AddComponentAfterRouteHook.md | 15 ++ docs/api/types/AddComponentBeforeRouteHook.md | 15 ++ docs/api/types/AddGlobalRouteHooks.md | 15 ++ docs/api/types/AfterHookContext.md | 19 ++ docs/api/types/AfterRouteHookRegistration.md | 25 +++ docs/api/types/BeforeHookContext.md | 19 ++ docs/api/types/BeforeRouteHookRegistration.md | 25 +++ docs/api/types/CreateRouteOptions.md | 68 +++++-- docs/api/types/CreatedRouteOptions.md | 21 +++ docs/api/types/PropsCallbackContext.md | 16 +- docs/api/types/Route.md | 10 +- docs/api/types/RouteHookAfterRunner.md | 15 ++ docs/api/types/RouteHookBeforeRunner.md | 15 ++ docs/api/types/RouteHookTiming.md | 5 + docs/api/types/RouterOptions.md | 2 +- docs/api/types/WithHooks.md | 45 +++++ 24 files changed, 394 insertions(+), 212 deletions(-) delete mode 100644 docs/api/hooks/onAfterRouteEnter.md create mode 100644 docs/api/types/AddComponentAfterRouteHook.md create mode 100644 docs/api/types/AddComponentBeforeRouteHook.md create mode 100644 docs/api/types/AddGlobalRouteHooks.md create mode 100644 docs/api/types/AfterHookContext.md create mode 100644 docs/api/types/AfterRouteHookRegistration.md create mode 100644 docs/api/types/BeforeHookContext.md create mode 100644 docs/api/types/BeforeRouteHookRegistration.md create mode 100644 docs/api/types/CreatedRouteOptions.md create mode 100644 docs/api/types/RouteHookAfterRunner.md create mode 100644 docs/api/types/RouteHookBeforeRunner.md create mode 100644 docs/api/types/RouteHookTiming.md create mode 100644 docs/api/types/WithHooks.md diff --git a/docs/api/compositions/useLink.md b/docs/api/compositions/useLink.md index 47ab2638..cedb4bd8 100644 --- a/docs/api/compositions/useLink.md +++ b/docs/api/compositions/useLink.md @@ -66,7 +66,7 @@ for navigating. | Parameter | Type | Description | | ------ | ------ | ------ | -| `resolvedRoute` | `MaybeRefOrGetter`\< \| `undefined` \| `Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: `CreateRouteOptionsMatched`\<`string`\>; `matches`: `CreateRouteOptionsMatched`\<`undefined` \| `string`\>[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | - | +| `resolvedRoute` | `MaybeRefOrGetter`\< \| `undefined` \| `Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md); `matches`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md)[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | - | | `options`? | `MaybeRefOrGetter`\<[`UseLinkOptions`](../types/UseLinkOptions.md)\> | RouterResolveOptions Same options as router resolve. | ### Returns @@ -92,7 +92,7 @@ for navigating. | Parameter | Type | Description | | ------ | ------ | ------ | -| `source` | `MaybeRefOrGetter`\< \| `undefined` \| `string` \| `Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: `CreateRouteOptionsMatched`\<`string`\>; `matches`: `CreateRouteOptionsMatched`\<`undefined` \| `string`\>[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | The name of the route or a valid URL. | +| `source` | `MaybeRefOrGetter`\< \| `undefined` \| `string` \| `Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md); `matches`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md)[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | The name of the route or a valid URL. | | `paramsOrOptions`? | `MaybeRefOrGetter`\< \| `Record`\<`PropertyKey`, `unknown`\> \| [`UseLinkOptions`](../types/UseLinkOptions.md)\> | - | | `maybeOptions`? | `MaybeRefOrGetter`\<[`UseLinkOptions`](../types/UseLinkOptions.md)\> | - | diff --git a/docs/api/functions/createExternalRoute.md b/docs/api/functions/createExternalRoute.md index 52c0aa82..59fc5d42 100644 --- a/docs/api/functions/createExternalRoute.md +++ b/docs/api/functions/createExternalRoute.md @@ -21,7 +21,7 @@ function createExternalRoute(options) | Parameter | Type | | ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>\> & `WithHost`\<`THost`\> & `WithoutParent` | +| `options` | [`WithHooks`](../types/WithHooks.md) & `object` & `WithHost`\<`THost`\> & `WithoutParent` | ### Returns @@ -37,7 +37,7 @@ function createExternalRoute(option | Type Parameter | Default type | | ------ | ------ | -| `TParent` *extends* [`Route`](../types/Route.md)\<`string`, `Host`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>, `Record`\<`string`, [`Param`](../types/Param.md)\>, `undefined` \| `string`\> | - | +| `TParent` *extends* [`Route`](../types/Route.md)\<`string`, `Host`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>, `Record`\<`string`, [`Param`](../types/Param.md)\>, [`CreatedRouteOptions`](../types/CreatedRouteOptions.md)[]\> | - | | `TName` *extends* `undefined` \| `string` | `undefined` | | `TPath` *extends* \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | | `TQuery` *extends* \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | @@ -48,7 +48,7 @@ function createExternalRoute(option | Parameter | Type | | ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>\> & `WithoutHost` & `WithParent`\<`TParent`\> | +| `options` | [`WithHooks`](../types/WithHooks.md) & `object` & `WithoutHost` & `WithParent`\<`TParent`\> | ### Returns diff --git a/docs/api/functions/createRoute.md b/docs/api/functions/createRoute.md index 1c278187..f364687e 100644 --- a/docs/api/functions/createRoute.md +++ b/docs/api/functions/createRoute.md @@ -1,170 +1,23 @@ # Functions: createRoute() -## Call Signature - -```ts -function createRoute(options): Route, Host<"", {}>, ToPath, ToQuery, ToHash, TMeta, TState, TName> -``` - -### Type Parameters - -| Type Parameter | Default type | -| ------ | ------ | -| `TName` *extends* `undefined` \| `string` | `undefined` | -| `TPath` *extends* \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `TQuery` *extends* \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `THash` *extends* `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\> | `undefined` | -| `TMeta` *extends* `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> | -| `TState` *extends* `Record`\<`string`, [`Param`](../types/Param.md)\> | `Record`\<`string`, [`Param`](../types/Param.md)\> | - -### Parameters - -| Parameter | Type | -| ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `THash`, `TMeta`\> & `WithHooks` & WithoutComponents & (WithoutParent & (WithState\ \| WithoutState)) | - -### Returns - -[`Route`](../types/Route.md)\<`ToName`\<`TName`\>, `Host`\<`""`, \{\}\>, `ToPath`\<`TPath`\>, `ToQuery`\<`TQuery`\>, `ToHash`\<`THash`\>, `TMeta`, `TState`, `TName`\> - -## Call Signature - -```ts -function createRoute(options): Route, Host<"", {}>, CombinePath>, CombineQuery>, CombineHash>, CombineMeta, CombineState, TName | TParent["matches"][number]["name"]> -``` - -### Type Parameters - -| Type Parameter | Default type | -| ------ | ------ | -| `TParent` *extends* [`Route`](../types/Route.md)\<`string`, `Host`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>, `Record`\<`string`, [`Param`](../types/Param.md)\>, `undefined` \| `string`\> | - | -| `TName` *extends* `undefined` \| `string` | `undefined` | -| `TPath` *extends* \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `TQuery` *extends* \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `THash` *extends* `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\> | `undefined` | -| `TMeta` *extends* `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> | -| `TState` *extends* `Record`\<`string`, [`Param`](../types/Param.md)\> | `Record`\<`string`, [`Param`](../types/Param.md)\> | - -### Parameters - -| Parameter | Type | -| ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `THash`, `TMeta`\> & `WithHooks` & WithoutComponents & (WithParent\ & (WithoutState \| WithState\)) | - -### Returns - -[`Route`](../types/Route.md)\<`ToName`\<`TName`\>, `Host`\<`""`, \{\}\>, `CombinePath`\<`TParent`\[`"path"`\], `ToPath`\<`TPath`\>\>, `CombineQuery`\<`TParent`\[`"query"`\], `ToQuery`\<`TQuery`\>\>, `CombineHash`\<`TParent`\[`"hash"`\], `ToHash`\<`THash`\>\>, `CombineMeta`\<`TMeta`, `TParent`\[`"meta"`\]\>, `CombineState`\<`TState`, `TParent`\[`"state"`\]\>, `TName` \| `TParent`\[`"matches"`\]\[`number`\]\[`"name"`\]\> - -## Call Signature - ```ts -function createRoute(options): Route, Host<"", {}>, ToPath, ToQuery, ToHash, TMeta, TState, TName> +function createRoute(options, ...args): ToRoute extends TProps ? undefined : TProps> ``` -### Type Parameters - -| Type Parameter | Default type | -| ------ | ------ | -| `TComponent` *extends* `Component` | - | -| `TName` *extends* `undefined` \| `string` | `undefined` | -| `TPath` *extends* \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `TQuery` *extends* \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `THash` *extends* `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\> | `undefined` | -| `TMeta` *extends* `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> | -| `TState` *extends* `Record`\<`string`, [`Param`](../types/Param.md)\> | `Record`\<`string`, [`Param`](../types/Param.md)\> | - -### Parameters - -| Parameter | Type | -| ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `THash`, `TMeta`\> & `WithHooks` & WithComponent\, Host\<"", \{\}\>, ToPath\, ToQuery\, ToHash\, TMeta, TState, TName\>\> & (WithoutParent & (WithoutState \| WithState\<...\>)) | - -### Returns +## Type Parameters -[`Route`](../types/Route.md)\<`ToName`\<`TName`\>, `Host`\<`""`, \{\}\>, `ToPath`\<`TPath`\>, `ToQuery`\<`TQuery`\>, `ToHash`\<`THash`\>, `TMeta`, `TState`, `TName`\> - -## Call Signature - -```ts -function createRoute(options): Route, Host<"", {}>, CombinePath>, CombineQuery>, CombineHash>, CombineMeta, CombineState, TName | TParent["matches"][number]["name"]> -``` - -### Type Parameters - -| Type Parameter | Default type | -| ------ | ------ | -| `TComponent` *extends* `Component` | - | -| `TParent` *extends* [`Route`](../types/Route.md)\<`string`, `Host`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>, `Record`\<`string`, [`Param`](../types/Param.md)\>, `undefined` \| `string`\> | - | -| `TName` *extends* `undefined` \| `string` | `undefined` | -| `TPath` *extends* \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `TQuery` *extends* \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `THash` *extends* `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\> | `undefined` | -| `TMeta` *extends* `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> | -| `TState` *extends* `Record`\<`string`, [`Param`](../types/Param.md)\> | `Record`\<`string`, [`Param`](../types/Param.md)\> | - -### Parameters - -| Parameter | Type | -| ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `THash`, `TMeta`\> & `WithHooks` & WithComponent\, Host\<"", \{\}\>, CombinePath\\>, CombineQuery\<...\>, CombineHash\<...\>, CombineMeta\<...\>, CombineState\<...\>, TName \| TParent\["matches"\]\[number\]\["name"\]\>\> & (WithParent\<...\> & (WithoutState \| WithState\<...\>)) | - -### Returns - -[`Route`](../types/Route.md)\<`ToName`\<`TName`\>, `Host`\<`""`, \{\}\>, `CombinePath`\<`TParent`\[`"path"`\], `ToPath`\<`TPath`\>\>, `CombineQuery`\<`TParent`\[`"query"`\], `ToQuery`\<`TQuery`\>\>, `CombineHash`\<`TParent`\[`"hash"`\], `ToHash`\<`THash`\>\>, `CombineMeta`\<`TMeta`, `TParent`\[`"meta"`\]\>, `CombineState`\<`TState`, `TParent`\[`"state"`\]\>, `TName` \| `TParent`\[`"matches"`\]\[`number`\]\[`"name"`\]\> - -## Call Signature - -```ts -function createRoute(options): Route, Host<"", {}>, ToPath, ToQuery, ToHash, TMeta, TState, TName> -``` - -### Type Parameters - -| Type Parameter | Default type | -| ------ | ------ | -| `TComponents` *extends* `Record`\<`string`, `Component`\> | - | -| `TName` *extends* `undefined` \| `string` | `undefined` | -| `TPath` *extends* \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `TQuery` *extends* \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `THash` *extends* `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\> | `undefined` | -| `TMeta` *extends* `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> | -| `TState` *extends* `Record`\<`string`, [`Param`](../types/Param.md)\> | `Record`\<`string`, [`Param`](../types/Param.md)\> | - -### Parameters - -| Parameter | Type | -| ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `THash`, `TMeta`\> & `WithHooks` & WithComponents\, Host\<"", \{\}\>, ToPath\, ToQuery\, ToHash\, TMeta, TState, TName\>\> & (WithoutParent & (WithoutState \| WithState\<...\>)) | - -### Returns - -[`Route`](../types/Route.md)\<`ToName`\<`TName`\>, `Host`\<`""`, \{\}\>, `ToPath`\<`TPath`\>, `ToQuery`\<`TQuery`\>, `ToHash`\<`THash`\>, `TMeta`, `TState`, `TName`\> - -## Call Signature - -```ts -function createRoute(options): Route, Host<"", {}>, CombinePath>, CombineQuery>, CombineHash>, CombineMeta, CombineState, TName | TParent["matches"][number]["name"]> -``` - -### Type Parameters - -| Type Parameter | Default type | -| ------ | ------ | -| `TComponents` *extends* `Record`\<`string`, `Component`\> | - | -| `TParent` *extends* [`Route`](../types/Route.md)\<`string`, `Host`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>, `Record`\<`string`, [`Param`](../types/Param.md)\>, `undefined` \| `string`\> | - | -| `TName` *extends* `undefined` \| `string` | `undefined` | -| `TPath` *extends* \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `TQuery` *extends* \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\> | `undefined` | -| `THash` *extends* `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\> | `undefined` | -| `TMeta` *extends* `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> | -| `TState` *extends* `Record`\<`string`, [`Param`](../types/Param.md)\> | `Record`\<`string`, [`Param`](../types/Param.md)\> | +| Type Parameter | +| ------ | +| `TOptions` *extends* [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`undefined` \| `string`, \| `undefined` \| `string` \| `Path`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, \| `undefined` \| `string` \| `Query`\<`string`, `Record`\<`string`, `undefined` \| [`Param`](../types/Param.md)\>\>, `undefined` \| `string` \| `Hash`\<`undefined` \| `string`\>, `Record`\<`string`, `unknown`\>\> | +| `TProps` *extends* \| `PropsGetter`\<`TOptions`, `any`\[`any`\]\> \| `RoutePropsRecord`\<`TOptions`, `any`\[`any`\]\> \| `PropsGetter`\<`TOptions`, `__VLS_WithTemplateSlots`\<`DefineComponent`\<\{ `name`: `string`; \}, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, \{\}, `string`, `PublicProps`, `Readonly`\<\{ `name`: `string`; \}\> & `Readonly`\<\{\}\>, \{\}, \{\}, \{\}, \{\}, `string`, `ComponentProvideOptions`, `false`, \{\}, `any`\>, `Readonly`\<\{ `default`: (`props`) => `VNode`; \}\> & `object`\>\> | -### Parameters +## Parameters | Parameter | Type | | ------ | ------ | -| `options` | [`CreateRouteOptions`](../types/CreateRouteOptions.md)\<`TName`, `TPath`, `TQuery`, `THash`, `TMeta`\> & `WithHooks` & WithComponents\, Host\<"", \{\}\>, CombinePath\\>, ... 4 more ..., TName \| TParent\["matches"\]\[number\]\["name"\]\>\> & (WithParent\<...\> & (WithoutState \| WithState\<...\>)) | +| `options` | `TOptions` | +| ...`args` | `CreateRouteWithProps`\<`TOptions`, `TProps`\> | -### Returns +## Returns -[`Route`](../types/Route.md)\<`ToName`\<`TName`\>, `Host`\<`""`, \{\}\>, `CombinePath`\<`TParent`\[`"path"`\], `ToPath`\<`TPath`\>\>, `CombineQuery`\<`TParent`\[`"query"`\], `ToQuery`\<`TQuery`\>\>, `CombineHash`\<`TParent`\[`"hash"`\], `ToHash`\<`THash`\>\>, `CombineMeta`\<`TMeta`, `TParent`\[`"meta"`\]\>, `CombineState`\<`TState`, `TParent`\[`"state"`\]\>, `TName` \| `TParent`\[`"matches"`\]\[`number`\]\[`"name"`\]\> +`ToRoute`\<`TOptions`, `CreateRouteProps`\<`TOptions`\> *extends* `TProps` ? `undefined` : `TProps`\> diff --git a/docs/api/functions/createRouter.md b/docs/api/functions/createRouter.md index c2769aa8..5ff26eca 100644 --- a/docs/api/functions/createRouter.md +++ b/docs/api/functions/createRouter.md @@ -53,7 +53,7 @@ const router = createRouter(routes) ```ts function createRouter( - arrayOfRoutes, + routes, options?, plugins?): Router ``` @@ -72,7 +72,7 @@ Creates a router instance for a Vue application, equipped with methods for route | Parameter | Type | Description | | ------ | ------ | ------ | -| `arrayOfRoutes` | `TRoutes`[] | - | +| `routes` | `TRoutes`[] | [Routes](../types/Routes.md) An array of route definitions specifying the configuration of routes in the application. Use createRoute method to create the route definitions. | | `options`? | `TOptions` | [RouterOptions](../types/RouterOptions.md) for the router, including history mode and initial URL settings. | | `plugins`? | `TPlugin`[] | - | diff --git a/docs/api/hooks/onAfterRouteEnter.md b/docs/api/hooks/onAfterRouteEnter.md deleted file mode 100644 index 24f12334..00000000 --- a/docs/api/hooks/onAfterRouteEnter.md +++ /dev/null @@ -1,20 +0,0 @@ -# Hooks: onAfterRouteEnter() - -```ts -function onAfterRouteEnter(hook): RouteHookRemove -``` - -Registers a hook that is called after a route has been entered. Must be called during setup. -This allows performing actions right after the component becomes active, such as fetching data or setting up event listeners. - -## Parameters - -| Parameter | Type | -| ------ | ------ | -| `hook` | [`AfterRouteHook`](../types/AfterRouteHook.md) | - -## Returns - -[`RouteHookRemove`](../types/RouteHookRemove.md) - -A function that removes the added hook. diff --git a/docs/api/index.md b/docs/api/index.md index 44e4c01a..1899f85d 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -36,7 +36,6 @@ ## Hooks -- [onAfterRouteEnter](hooks/onAfterRouteEnter.md) - [onAfterRouteLeave](hooks/onAfterRouteLeave.md) - [onAfterRouteUpdate](hooks/onAfterRouteUpdate.md) - [onBeforeRouteLeave](hooks/onBeforeRouteLeave.md) @@ -46,14 +45,22 @@ - [AddAfterRouteHook](types/AddAfterRouteHook.md) - [AddBeforeRouteHook](types/AddBeforeRouteHook.md) +- [AddComponentAfterRouteHook](types/AddComponentAfterRouteHook.md) +- [AddComponentBeforeRouteHook](types/AddComponentBeforeRouteHook.md) +- [AddGlobalRouteHooks](types/AddGlobalRouteHooks.md) +- [AfterHookContext](types/AfterHookContext.md) - [AfterRouteHook](types/AfterRouteHook.md) - [AfterRouteHookContext](types/AfterRouteHookContext.md) - [AfterRouteHookLifecycle](types/AfterRouteHookLifecycle.md) +- [AfterRouteHookRegistration](types/AfterRouteHookRegistration.md) - [AfterRouteHookResponse](types/AfterRouteHookResponse.md) +- [BeforeHookContext](types/BeforeHookContext.md) - [BeforeRouteHook](types/BeforeRouteHook.md) - [BeforeRouteHookContext](types/BeforeRouteHookContext.md) - [BeforeRouteHookLifecycle](types/BeforeRouteHookLifecycle.md) +- [BeforeRouteHookRegistration](types/BeforeRouteHookRegistration.md) - [BeforeRouteHookResponse](types/BeforeRouteHookResponse.md) +- [CreatedRouteOptions](types/CreatedRouteOptions.md) - [CreateRouteOptions](types/CreateRouteOptions.md) - [Param](types/Param.md) - [ParamExtras](types/ParamExtras.md) @@ -76,9 +83,12 @@ - [ResolvedRoute](types/ResolvedRoute.md) - [Route](types/Route.md) - [RouteHook](types/RouteHook.md) +- [RouteHookAfterRunner](types/RouteHookAfterRunner.md) +- [RouteHookBeforeRunner](types/RouteHookBeforeRunner.md) - [RouteHookLifecycle](types/RouteHookLifecycle.md) - [RouteHookRemove](types/RouteHookRemove.md) - [RouteHookResponse](types/RouteHookResponse.md) +- [RouteHookTiming](types/RouteHookTiming.md) - [RouteMeta](types/RouteMeta.md) - [Router](types/Router.md) - [RouterOptions](types/RouterOptions.md) @@ -92,3 +102,4 @@ - [UrlParts](types/UrlParts.md) - [UseLink](types/UseLink.md) - [UseLinkOptions](types/UseLinkOptions.md) +- [WithHooks](types/WithHooks.md) diff --git a/docs/api/type-guards/isRoute.md b/docs/api/type-guards/isRoute.md index c272a0f0..788cc92b 100644 --- a/docs/api/type-guards/isRoute.md +++ b/docs/api/type-guards/isRoute.md @@ -3,7 +3,7 @@ ## Call Signature ```ts -function isRoute(route): route is RouterRoute; matches: CreateRouteOptionsMatched[]; name: string; params: { (key: string): any; (key: number): any }; query: URLSearchParams; state: { (key: string): any; (key: number): any } }>> +function isRoute(route): route is RouterRoute> ``` A type guard for determining if a value is a valid RouterRoute. @@ -16,7 +16,7 @@ A type guard for determining if a value is a valid RouterRoute. ### Returns -route is RouterRoute\; matches: CreateRouteOptionsMatched\\[\]; name: string; params: \{ (key: string): any; (key: number): any \}; query: URLSearchParams; state: \{ (key: string): any; (key: number): any \} \}\>\> +`route is RouterRoute>` `true` if the value is a valid RouterRoute, otherwise `false`. @@ -35,7 +35,7 @@ A type guard for determining if a value is a valid RouterRoute with an exact mat | Type Parameter | | ------ | -| `TRoute` *extends* [`RouterRoute`](../types/RouterRoute.md)\<`Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: `CreateRouteOptionsMatched`\<`string`\>; `matches`: `CreateRouteOptionsMatched`\<`undefined` \| `string`\>[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | +| `TRoute` *extends* [`RouterRoute`](../types/RouterRoute.md)\<`Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md); `matches`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md)[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | | `TRouteName` *extends* `string` | ### Parameters @@ -67,7 +67,7 @@ A type guard for determining if a value is a valid RouterRoute with a partial ma | Type Parameter | | ------ | -| `TRoute` *extends* [`RouterRoute`](../types/RouterRoute.md)\<`Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: `CreateRouteOptionsMatched`\<`string`\>; `matches`: `CreateRouteOptionsMatched`\<`undefined` \| `string`\>[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | +| `TRoute` *extends* [`RouterRoute`](../types/RouterRoute.md)\<`Readonly`\<\{ `hash`: `string`; `href`: [`Url`](../types/Url.md); `id`: `string`; `matched`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md); `matches`: [`CreatedRouteOptions`](../types/CreatedRouteOptions.md)[]; `name`: `string`; `params`: \{\}; `query`: `URLSearchParams`; `state`: \{\}; \}\>\> | | `TRouteName` *extends* `string` | ### Parameters diff --git a/docs/api/typedoc-sidebar.json b/docs/api/typedoc-sidebar.json index 1a32a60f..9cb27619 100644 --- a/docs/api/typedoc-sidebar.json +++ b/docs/api/typedoc-sidebar.json @@ -109,10 +109,6 @@ "text": "Hooks", "collapsed": true, "items": [ - { - "text": "onAfterRouteEnter", - "link": "/api/hooks/onAfterRouteEnter.md" - }, { "text": "onAfterRouteLeave", "link": "/api/hooks/onAfterRouteLeave.md" @@ -143,6 +139,22 @@ "text": "AddBeforeRouteHook", "link": "/api/types/AddBeforeRouteHook.md" }, + { + "text": "AddComponentAfterRouteHook", + "link": "/api/types/AddComponentAfterRouteHook.md" + }, + { + "text": "AddComponentBeforeRouteHook", + "link": "/api/types/AddComponentBeforeRouteHook.md" + }, + { + "text": "AddGlobalRouteHooks", + "link": "/api/types/AddGlobalRouteHooks.md" + }, + { + "text": "AfterHookContext", + "link": "/api/types/AfterHookContext.md" + }, { "text": "AfterRouteHook", "link": "/api/types/AfterRouteHook.md" @@ -155,10 +167,18 @@ "text": "AfterRouteHookLifecycle", "link": "/api/types/AfterRouteHookLifecycle.md" }, + { + "text": "AfterRouteHookRegistration", + "link": "/api/types/AfterRouteHookRegistration.md" + }, { "text": "AfterRouteHookResponse", "link": "/api/types/AfterRouteHookResponse.md" }, + { + "text": "BeforeHookContext", + "link": "/api/types/BeforeHookContext.md" + }, { "text": "BeforeRouteHook", "link": "/api/types/BeforeRouteHook.md" @@ -171,10 +191,18 @@ "text": "BeforeRouteHookLifecycle", "link": "/api/types/BeforeRouteHookLifecycle.md" }, + { + "text": "BeforeRouteHookRegistration", + "link": "/api/types/BeforeRouteHookRegistration.md" + }, { "text": "BeforeRouteHookResponse", "link": "/api/types/BeforeRouteHookResponse.md" }, + { + "text": "CreatedRouteOptions", + "link": "/api/types/CreatedRouteOptions.md" + }, { "text": "CreateRouteOptions", "link": "/api/types/CreateRouteOptions.md" @@ -263,6 +291,14 @@ "text": "RouteHook", "link": "/api/types/RouteHook.md" }, + { + "text": "RouteHookAfterRunner", + "link": "/api/types/RouteHookAfterRunner.md" + }, + { + "text": "RouteHookBeforeRunner", + "link": "/api/types/RouteHookBeforeRunner.md" + }, { "text": "RouteHookLifecycle", "link": "/api/types/RouteHookLifecycle.md" @@ -275,6 +311,10 @@ "text": "RouteHookResponse", "link": "/api/types/RouteHookResponse.md" }, + { + "text": "RouteHookTiming", + "link": "/api/types/RouteHookTiming.md" + }, { "text": "RouteMeta", "link": "/api/types/RouteMeta.md" @@ -326,6 +366,10 @@ { "text": "UseLinkOptions", "link": "/api/types/UseLinkOptions.md" + }, + { + "text": "WithHooks", + "link": "/api/types/WithHooks.md" } ] } diff --git a/docs/api/types/AddComponentAfterRouteHook.md b/docs/api/types/AddComponentAfterRouteHook.md new file mode 100644 index 00000000..a4e08c64 --- /dev/null +++ b/docs/api/types/AddComponentAfterRouteHook.md @@ -0,0 +1,15 @@ +# Types: AddComponentAfterRouteHook() + +```ts +type AddComponentAfterRouteHook = (hook) => RouteHookRemove; +``` + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| `hook` | [`AfterRouteHookRegistration`](AfterRouteHookRegistration.md) | + +## Returns + +[`RouteHookRemove`](RouteHookRemove.md) diff --git a/docs/api/types/AddComponentBeforeRouteHook.md b/docs/api/types/AddComponentBeforeRouteHook.md new file mode 100644 index 00000000..7260fdb4 --- /dev/null +++ b/docs/api/types/AddComponentBeforeRouteHook.md @@ -0,0 +1,15 @@ +# Types: AddComponentBeforeRouteHook() + +```ts +type AddComponentBeforeRouteHook = (hook) => RouteHookRemove; +``` + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| `hook` | [`BeforeRouteHookRegistration`](BeforeRouteHookRegistration.md) | + +## Returns + +[`RouteHookRemove`](RouteHookRemove.md) diff --git a/docs/api/types/AddGlobalRouteHooks.md b/docs/api/types/AddGlobalRouteHooks.md new file mode 100644 index 00000000..e593fa4c --- /dev/null +++ b/docs/api/types/AddGlobalRouteHooks.md @@ -0,0 +1,15 @@ +# Types: AddGlobalRouteHooks() + +```ts +type AddGlobalRouteHooks = (hooks) => void; +``` + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| `hooks` | `RouteHooks` | + +## Returns + +`void` diff --git a/docs/api/types/AfterHookContext.md b/docs/api/types/AfterHookContext.md new file mode 100644 index 00000000..57d624df --- /dev/null +++ b/docs/api/types/AfterHookContext.md @@ -0,0 +1,19 @@ +# Types: AfterHookContext + +```ts +type AfterHookContext = object; +``` + +## Type declaration + +### from + +```ts +from: ResolvedRoute | null; +``` + +### to + +```ts +to: ResolvedRoute; +``` diff --git a/docs/api/types/AfterRouteHookRegistration.md b/docs/api/types/AfterRouteHookRegistration.md new file mode 100644 index 00000000..e227e61a --- /dev/null +++ b/docs/api/types/AfterRouteHookRegistration.md @@ -0,0 +1,25 @@ +# Types: AfterRouteHookRegistration + +```ts +type AfterRouteHookRegistration = object; +``` + +## Type declaration + +### depth + +```ts +depth: number; +``` + +### hook + +```ts +hook: AfterRouteHook; +``` + +### lifecycle + +```ts +lifecycle: "onAfterRouteEnter" | "onAfterRouteUpdate" | "onAfterRouteLeave"; +``` diff --git a/docs/api/types/BeforeHookContext.md b/docs/api/types/BeforeHookContext.md new file mode 100644 index 00000000..960146cd --- /dev/null +++ b/docs/api/types/BeforeHookContext.md @@ -0,0 +1,19 @@ +# Types: BeforeHookContext + +```ts +type BeforeHookContext = object; +``` + +## Type declaration + +### from + +```ts +from: ResolvedRoute | null; +``` + +### to + +```ts +to: ResolvedRoute; +``` diff --git a/docs/api/types/BeforeRouteHookRegistration.md b/docs/api/types/BeforeRouteHookRegistration.md new file mode 100644 index 00000000..19926ac1 --- /dev/null +++ b/docs/api/types/BeforeRouteHookRegistration.md @@ -0,0 +1,25 @@ +# Types: BeforeRouteHookRegistration + +```ts +type BeforeRouteHookRegistration = object; +``` + +## Type declaration + +### depth + +```ts +depth: number; +``` + +### hook + +```ts +hook: BeforeRouteHook; +``` + +### lifecycle + +```ts +lifecycle: "onBeforeRouteEnter" | "onBeforeRouteUpdate" | "onBeforeRouteLeave"; +``` diff --git a/docs/api/types/CreateRouteOptions.md b/docs/api/types/CreateRouteOptions.md index d32c6da6..ffdc3b9c 100644 --- a/docs/api/types/CreateRouteOptions.md +++ b/docs/api/types/CreateRouteOptions.md @@ -1,20 +1,32 @@ # Types: CreateRouteOptions\ ```ts -type CreateRouteOptions = object; +type CreateRouteOptions = WithHooks & object; ``` -## Type Parameters +## Type declaration -| Type Parameter | Default type | -| ------ | ------ | -| `TName` *extends* `string` \| `undefined` | `string` \| `undefined` | -| `TPath` *extends* `string` \| `Path` \| `undefined` | `string` \| `Path` \| `undefined` | -| `TQuery` *extends* `string` \| `Query` \| `undefined` | `string` \| `Query` \| `undefined` | -| `THash` *extends* `string` \| `Hash` \| `undefined` | `string` \| `Hash` \| `undefined` | -| `TMeta` *extends* [`RouteMeta`](RouteMeta.md) | [`RouteMeta`](RouteMeta.md) | +### component? -## Type declaration +```ts +optional component: Component; +``` + +An optional component to render when this route is matched. + +#### Default + +```ts +RouterView +``` + +### components? + +```ts +optional components: Record; +``` + +An object of named components to render using named views ### hash? @@ -40,6 +52,14 @@ optional name: TName; Name for route, used to create route keys and in navigation. +### parent? + +```ts +optional parent: Route; +``` + +An optional parent route to nest this route under. + ### path? ```ts @@ -56,6 +76,16 @@ optional prefetch: PrefetchConfig; Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch. +### ~~props?~~ + +```ts +optional props: never; +``` + +Props have been moved to the second argument of `createRoute`. This property can no longer be used. + +#### Deprecated + ### query? ```ts @@ -63,3 +93,21 @@ optional query: TQuery; ``` Query (aka search) part of URL. + +### state? + +```ts +optional state: Record; +``` + +Type params for additional data intended to be stored in history state, all keys will be optional unless a default is provided. + +## Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `TName` *extends* `string` \| `undefined` | `string` \| `undefined` | +| `TPath` *extends* `string` \| `Path` \| `undefined` | `string` \| `Path` \| `undefined` | +| `TQuery` *extends* `string` \| `Query` \| `undefined` | `string` \| `Query` \| `undefined` | +| `THash` *extends* `string` \| `Hash` \| `undefined` | `string` \| `Hash` \| `undefined` | +| `TMeta` *extends* [`RouteMeta`](RouteMeta.md) | [`RouteMeta`](RouteMeta.md) | diff --git a/docs/api/types/CreatedRouteOptions.md b/docs/api/types/CreatedRouteOptions.md new file mode 100644 index 00000000..d2124a73 --- /dev/null +++ b/docs/api/types/CreatedRouteOptions.md @@ -0,0 +1,21 @@ +# Types: CreatedRouteOptions + +```ts +type CreatedRouteOptions = Omit & WithHooks & object; +``` + +The Route properties originally provided to `createRoute`. The only change is normalizing meta to always default to an empty object. + +## Type declaration + +### id + +```ts +id: string; +``` + +### props? + +```ts +optional props: unknown; +``` diff --git a/docs/api/types/PropsCallbackContext.md b/docs/api/types/PropsCallbackContext.md index bec2e0c0..0063d485 100644 --- a/docs/api/types/PropsCallbackContext.md +++ b/docs/api/types/PropsCallbackContext.md @@ -1,13 +1,25 @@ -# Types: PropsCallbackContext +# Types: PropsCallbackContext\ ```ts -type PropsCallbackContext = object; +type PropsCallbackContext = object; ``` Context provided to props callback functions +## Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `TParent` *extends* [`Route`](Route.md) \| `undefined` | [`Route`](Route.md) \| `undefined` | + ## Type declaration +### parent + +```ts +parent: PropsCallbackParent; +``` + ### push ```ts diff --git a/docs/api/types/Route.md b/docs/api/types/Route.md index 202040a4..cfe3f3dc 100644 --- a/docs/api/types/Route.md +++ b/docs/api/types/Route.md @@ -1,7 +1,7 @@ -# Types: Route\ +# Types: Route\ ```ts -type Route = object; +type Route = object; ``` Represents the structure of a route within the application. Return value of `createRoute` @@ -17,7 +17,7 @@ Represents the structure of a route within the application. Return value of `cre | `THash` *extends* `Hash` | `Hash` | - | | `TMeta` *extends* [`RouteMeta`](RouteMeta.md) | [`RouteMeta`](RouteMeta.md) | - | | `TState` *extends* `Record`\<`string`, [`Param`](Param.md)\> | `Record`\<`string`, [`Param`](Param.md)\> | - | -| `TMatchNames` *extends* `string` \| `undefined` | `string` \| `undefined` | - | +| `TMatches` *extends* [`CreatedRouteOptions`](CreatedRouteOptions.md)[] | [`CreatedRouteOptions`](CreatedRouteOptions.md)[] | - | ## Type declaration @@ -48,7 +48,7 @@ Unique identifier for the route, generated by router. ### matched ```ts -matched: CreateRouteOptionsMatched; +matched: LastInArray; ``` The specific route properties that were matched in the current route. @@ -56,7 +56,7 @@ The specific route properties that were matched in the current route. ### matches ```ts -matches: CreateRouteOptionsMatched[]; +matches: TMatches; ``` The specific route properties that were matched in the current route, including any ancestors. diff --git a/docs/api/types/RouteHookAfterRunner.md b/docs/api/types/RouteHookAfterRunner.md new file mode 100644 index 00000000..870cbd5f --- /dev/null +++ b/docs/api/types/RouteHookAfterRunner.md @@ -0,0 +1,15 @@ +# Types: RouteHookAfterRunner() + +```ts +type RouteHookAfterRunner = (context) => Promise; +``` + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| `context` | [`AfterHookContext`](AfterHookContext.md) | + +## Returns + +`Promise`\<[`AfterRouteHookResponse`](AfterRouteHookResponse.md)\> diff --git a/docs/api/types/RouteHookBeforeRunner.md b/docs/api/types/RouteHookBeforeRunner.md new file mode 100644 index 00000000..74e6c213 --- /dev/null +++ b/docs/api/types/RouteHookBeforeRunner.md @@ -0,0 +1,15 @@ +# Types: RouteHookBeforeRunner() + +```ts +type RouteHookBeforeRunner = (context) => Promise; +``` + +## Parameters + +| Parameter | Type | +| ------ | ------ | +| `context` | [`BeforeHookContext`](BeforeHookContext.md) | + +## Returns + +`Promise`\<[`BeforeRouteHookResponse`](BeforeRouteHookResponse.md)\> diff --git a/docs/api/types/RouteHookTiming.md b/docs/api/types/RouteHookTiming.md new file mode 100644 index 00000000..722e3e85 --- /dev/null +++ b/docs/api/types/RouteHookTiming.md @@ -0,0 +1,5 @@ +# Types: RouteHookTiming + +```ts +type RouteHookTiming = "global" | "component"; +``` diff --git a/docs/api/types/RouterOptions.md b/docs/api/types/RouterOptions.md index 53f072ec..c2694571 100644 --- a/docs/api/types/RouterOptions.md +++ b/docs/api/types/RouterOptions.md @@ -1,7 +1,7 @@ # Types: RouterOptions ```ts -type RouterOptions = object; +type RouterOptions = WithHooks & object; ``` Options to initialize a [Router](Router.md) instance. diff --git a/docs/api/types/WithHooks.md b/docs/api/types/WithHooks.md new file mode 100644 index 00000000..70aeb306 --- /dev/null +++ b/docs/api/types/WithHooks.md @@ -0,0 +1,45 @@ +# Types: WithHooks + +```ts +type WithHooks = object; +``` + +Defines route hooks that can be applied before entering, updating, or leaving a route, as well as after these events. + +## Type declaration + +### onAfterRouteEnter? + +```ts +optional onAfterRouteEnter: MaybeArray; +``` + +### onAfterRouteLeave? + +```ts +optional onAfterRouteLeave: MaybeArray; +``` + +### onAfterRouteUpdate? + +```ts +optional onAfterRouteUpdate: MaybeArray; +``` + +### onBeforeRouteEnter? + +```ts +optional onBeforeRouteEnter: MaybeArray; +``` + +### onBeforeRouteLeave? + +```ts +optional onBeforeRouteLeave: MaybeArray; +``` + +### onBeforeRouteUpdate? + +```ts +optional onBeforeRouteUpdate: MaybeArray; +``` From 36a96b0938fb6857ccf35df99913b774f91265b9 Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Wed, 22 Jan 2025 18:07:38 -0600 Subject: [PATCH 2/2] Update props core concepts doc --- docs/core-concepts/component-props.md | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/core-concepts/component-props.md b/docs/core-concepts/component-props.md index 631535b2..4fae03eb 100644 --- a/docs/core-concepts/component-props.md +++ b/docs/core-concepts/component-props.md @@ -40,6 +40,42 @@ const user = createRoute({ }) ``` +## Parent Props + +The [callback context](/core-concepts/component-props#context) includes a `parent` property which contains the name and props of the parent route. This can be useful for passing down data to child components. + +```ts +const blogPost = createRoute({ + name: 'blog', + path: '/blog/[blogPostId]' +}, async (route) => { + const post = await getBlockPostById(route.params.blogPostId) + + return { + post + } +}) + +const blogPostTabs = createRoute({ + parent: blogPost, + name: 'tabs', + query: '?tab=[tab]' + component: PostTabs, +}, async (route, { parent }) => { + const tab = route.query.tab + const { post } = await parent.props + + return { + tab, + post + } +}) +``` + +:::warning +Awaiting parent props will create a waterfall of async operations which can make your app feel sluggish. +::: + ## Context The router provides a second `context` argument to your props callback. The context will always include: @@ -47,6 +83,7 @@ The router provides a second `context` argument to your props callback. The cont | Property | Description | | ---- | ---- | | push | Convenient way to move the user from wherever they were to a new route. | +| parent | And object containing the name and props of the parent route. | | replace | Same as push, but with `options: { replace: true }`. | | reject | Trigger a [rejection](/advanced-concepts/rejections) for the router to handle |