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

router.ts

104 lines4.1 KB

1import { RouterCore } from '@tanstack/router-core'
2import { getStoreFactory } from './routerStores'
3import type { RouterHistory } from '@tanstack/history'
4import type {
5 AnyRoute,
6 CreateRouterFn,
7 RouterConstructorOptions,
8 TrailingSlashOption,
9} from '@tanstack/router-core'
10import type {
11 ErrorRouteComponent,
12 NotFoundRouteComponent,
13 RouteComponent,
14} from './route'
15import type { JSX } from 'solid-js'
16​
17declare module '@tanstack/router-core' {
18 export interface RouterOptionsExtensions {
19 /**
20 * The default `component` a route should use if no component is provided.
21 *
22 * @default Outlet
23 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultcomponent-property)
24 */
25 defaultComponent?: RouteComponent
26 /**
27 * The default `errorComponent` a route should use if no error component is provided.
28 *
29 * @default ErrorComponent
30 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaulterrorcomponent-property)
31 * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
32 */
33 defaultErrorComponent?: ErrorRouteComponent
34 /**
35 * The default `pendingComponent` a route should use if no pending component is provided.
36 *
37 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultpendingcomponent-property)
38 * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#showing-a-pending-component)
39 */
40 defaultPendingComponent?: RouteComponent
41 /**
42 * The default `notFoundComponent` a route should use if no notFound component is provided.
43 *
44 * @default NotFound
45 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
46 * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/not-found-errors#default-router-wide-not-found-handling)
47 */
48 defaultNotFoundComponent?: NotFoundRouteComponent
49 /**
50 * A component that will be used to wrap the entire router.
51 *
52 * This is useful for providing a context to the entire router.
53 *
54 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#wrap-property)
55 */
56 Wrap?: (props: { children: any }) => JSX.Element
57 /**
58 * A component that will be used to wrap the inner contents of the router.
59 *
60 * This is useful for providing a context to the inner contents of the router where you also need access to the router context and hooks.
61 *
62 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#innerwrap-property)
63 */
64 InnerWrap?: (props: { children: any }) => JSX.Element
65​
66 /**
67 * The default `onCatch` handler for errors caught by the Router ErrorBoundary
68 *
69 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)
70 * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)
71 */
72 defaultOnCatch?: (error: Error) => void
73 }
75​
76export const createRouter: CreateRouterFn = (options) => {
77 return new Router(options)
79​
80export class Router<
81 in out TRouteTree extends AnyRoute,
82 in out TTrailingSlashOption extends TrailingSlashOption = 'never',
83 in out TDefaultStructuralSharingOption extends boolean = false,
84 in out TRouterHistory extends RouterHistory = RouterHistory,
85 in out TDehydrated extends Record<string, any> = Record<string, any>,
86> extends RouterCore<
87 TRouteTree,
88 TTrailingSlashOption,
89 TDefaultStructuralSharingOption,
90 TRouterHistory,
91 TDehydrated
92> {
93 constructor(
94 options: RouterConstructorOptions<
95 TRouteTree,
96 TTrailingSlashOption,
97 TDefaultStructuralSharingOption,
98 TRouterHistory,
99 TDehydrated
100 >,
101 ) {
102 super(options, getStoreFactory)
103 }