Open History to see the last commit
1import * as React from 'react'
2import warning from 'tiny-warning'
3import { DefaultGlobalNotFound } from './not-found'
4import type { AnyRoute, AnyRouter } from '@tanstack/router-core'
5β
6/**
7 * Renders a not found component for a route when no matching route is found.
8 *
9 * @param router - The router instance containing the route configuration
10 * @param route - The route that triggered the not found state
11 * @param data - Additional data to pass to the not found component
12 * @returns The rendered not found component or a default fallback component
13 */
14export function renderRouteNotFound(
15 router: AnyRouter,
16 route: AnyRoute,
17 data: any,
18) {
19 if (!route.options.notFoundComponent) {
20 if (router.options.defaultNotFoundComponent) {
21 return <router.options.defaultNotFoundComponent {...data} />
22 }
23β
24 if (process.env.NODE_ENV === 'development') {
25 warning(
26 route.options.notFoundComponent,
27 `A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`,
28 )
29 }
30β
31 return <DefaultGlobalNotFound />
32 }
33β
34 return <route.options.notFoundComponent {...data} />
35}