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

__root.tsx

70 lines1.6 KB

1import * as React from 'react'
2import {
3 Link,
4 Outlet,
5 createRootRouteWithContext,
6} from '@tanstack/react-router'
7import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
8import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
9import type { QueryClient } from '@tanstack/react-query'
10​
11export const Route = createRootRouteWithContext<{
12 queryClient: QueryClient
13}>()({
14 component: RootComponent,
15 notFoundComponent: () => {
16 return (
17 <div>
18 <p>This is the notFoundComponent configured on root route</p>
19 <Link to="/">Start Over</Link>
20 </div>
21 )
22 },
23})
24​
25function RootComponent() {
26 return (
27 <>
28 <div className="p-2 flex gap-2 text-lg">
29 <Link
30 to="/"
31 activeProps={{
32 className: 'font-bold',
33 }}
34 activeOptions={{ exact: true }}
35 >
36 Home
37 </Link>{' '}
38 <Link
39 to="/posts"
40 activeProps={{
41 className: 'font-bold',
42 }}
43 >
44 Posts
45 </Link>{' '}
46 <Link
47 to="/route-a"
48 activeProps={{
49 className: 'font-bold',
50 }}
51 >
52 Pathless Layout
53 </Link>{' '}
54 <Link
55 // @ts-expect-error
56 to="/this-route-does-not-exist"
57 activeProps={{
58 className: 'font-bold',
59 }}
60 >
61 This Route Does Not Exist
62 </Link>
63 </div>
64 <hr />
65 <Outlet />
66 <ReactQueryDevtools buttonPosition="top-right" />
67 <TanStackRouterDevtools position="bottom-right" />
68 </>
69 )