Skip to content

Commit

Permalink
fix(react-router): explicitly set the default notFoundMode and upda…
Browse files Browse the repository at this point in the history
…te the RouterOptions JSDoc comments (#2133)

* fix(react-router): set the default `notFoundMode` during instantiation

* docs: update `RouterOptions` with `notFoundMode` and `defaultViewTransition`
  • Loading branch information
SeanCassiere committed Aug 15, 2024
1 parent 2c9967d commit c66e1b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 18 additions & 1 deletion docs/framework/react/api/router/RouterOptionsType.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 11 additions & 3 deletions packages/react-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -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'
Expand Down Expand Up @@ -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 ?? {
Expand Down

0 comments on commit c66e1b5

Please sign in to comment.