Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

renderRouteNotFound.tsx

26 lines960 Bytes

1import warning from 'tiny-warning'
2import { DefaultGlobalNotFound } from './not-found'
3import type { AnyRoute, AnyRouter } from '@tanstack/router-core'
4​
5export function renderRouteNotFound(
6 router: AnyRouter,
7 route: AnyRoute,
8 data: any,
9) {
10 if (!route.options.notFoundComponent) {
11 if (router.options.defaultNotFoundComponent) {
12 return <router.options.defaultNotFoundComponent data={data} />
13 }
14​
15 if (process.env.NODE_ENV === 'development') {
16 warning(
17 route.options.notFoundComponent,
18 `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 (<div>Not Found<div>)`,
19 )
20 }
21​
22 return <DefaultGlobalNotFound />
23 }
24​
25 return <route.options.notFoundComponent data={data} />