From c66e1b55eb60138991ef25c2f6d7754d737ba6b3 Mon Sep 17 00:00:00 2001 From: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:30:06 +1200 Subject: [PATCH] fix(react-router): explicitly set the default `notFoundMode` and update the RouterOptions JSDoc comments (#2133) * fix(react-router): set the default `notFoundMode` during instantiation * docs: update `RouterOptions` with `notFoundMode` and `defaultViewTransition` --- .../react/api/router/RouterOptionsType.md | 19 ++++++++++++++++++- packages/react-router/src/router.ts | 14 +++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/framework/react/api/router/RouterOptionsType.md b/docs/framework/react/api/router/RouterOptionsType.md index 251de68133..2625db731b 100644 --- a/docs/framework/react/api/router/RouterOptionsType.md +++ b/docs/framework/react/api/router/RouterOptionsType.md @@ -126,6 +126,14 @@ The `RouterOptions` type accepts an object with the following properties and met - Optional - The default `onCatch` handler for errors caught by the Router ErrorBoundary +### `defaultViewTransition` property + +- Type: `boolean` +- Optional +- If `true`, route navigations will called using `document.startViewTransition()`. +- If the browser does not support this api, this option will be ignored. +- See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works. + ### `caseSensitive` property - Type: `boolean` @@ -176,7 +184,8 @@ The `RouterOptions` type accepts an object with the following properties and met - Type: `React.Component` - Optional - A component that will be used to wrap the entire router. This is useful for providing a context to the entire router. Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error. - **Example** + +**Example** ```tsx import { createRouter } from '@tanstack/react-router' @@ -214,8 +223,16 @@ const router = createRouter({ }) ``` +### `notFoundMode` property + +- Type: `'root' | 'fuzzy'` +- Optional +- Defaults to `'fuzzy'` +- This property controls how TanStack Router will handle scenarios where it cannot find a route to match the current location. See the [Not Found Errors guide](../../guide/not-found-errors.md) for more information. + ### `notFoundRoute` property +- **Deprecated** - Type: `NotFoundRoute` - Optional - A route that will be used as the default not found route for every branch of the route tree. This can be overridden on a per-branch basis by providing a not found route to the `NotFoundRoute` option on the root route of the branch. diff --git a/packages/react-router/src/router.ts b/packages/react-router/src/router.ts index 0c7b0ef464..859b4a4809 100644 --- a/packages/react-router/src/router.ts +++ b/packages/react-router/src/router.ts @@ -249,10 +249,9 @@ export interface RouterOptions< */ defaultPreloadStaleTime?: number /** - * Defaults to `routerOptions.defaultGcTime`, which defaults to 30 minutes. - * * The default `defaultPreloadGcTime` a route should use if no preloadGcTime is provided. * + * @default 1_800_000 `(30 minutes)` * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadgctime-property) * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading) */ @@ -265,10 +264,18 @@ export interface RouterOptions< */ defaultOnCatch?: (error: Error, errorInfo: React.ErrorInfo) => void /** - * If set to `true`, all navigation actions will wrapped in `document.startViewTransition()`. + * If `true`, route navigations will called using `document.startViewTransition()`. + * + * If the browser does not support this api, this option will be ignored. + * + * See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works. + * + * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultviewtransition-property) */ defaultViewTransition?: boolean /** + * @default 'fuzzy' + * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundmode-property) * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#the-notfoundmode-option) */ notFoundMode?: 'root' | 'fuzzy' @@ -634,6 +641,7 @@ export class Router< defaultPendingMinMs: 500, context: undefined!, ...options, + notFoundMode: options.notFoundMode ?? 'fuzzy', stringifySearch: options.stringifySearch ?? defaultStringifySearch, parseSearch: options.parseSearch ?? defaultParseSearch, transformer: options.transformer ?? {