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

__root.tsx

89 lines2.0 KB

1import * as React from 'react'
2import { Link, Outlet, createRootRoute } from '@tanstack/react-router'
3import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
4​
5export const Route = createRootRoute({
6 component: RootComponent,
7 notFoundComponent: () => {
8 return (
9 <div>
10 <p>This is the notFoundComponent configured on root route</p>
11 <Link to="/">Start Over</Link>
12 </div>
13 )
14 },
15})
16​
17function RootComponent() {
18 return (
19 <>
20 <div className="p-2 flex gap-2 text-lg border-b">
21 <Link
22 to="/"
23 activeProps={{
24 className: 'font-bold',
25 }}
26 activeOptions={{ exact: true }}
27 >
28 Home
29 </Link>{' '}
30 <Link
31 to="/posts"
32 activeProps={{
33 className: 'font-bold',
34 }}
35 >
36 Posts
37 </Link>{' '}
38 <Link
39 to="/layout-a"
40 activeProps={{
41 className: 'font-bold',
42 }}
43 >
44 Layout
45 </Link>{' '}
46 <Link
47 to="/without-loader"
48 activeProps={{
49 className: 'font-bold',
50 }}
51 >
52 without-loader
53 </Link>{' '}
54 <Link
55 to="/shared-singleton"
56 activeProps={{
57 className: 'font-bold',
58 }}
59 data-testid="shared-singleton-link"
60 >
61 shared-singleton
62 </Link>{' '}
63 <Link
64 // @ts-expect-error
65 to="/this-route-does-not-exist"
66 activeProps={{
67 className: 'font-bold',
68 }}
69 >
70 This Route Does Not Exist
71 </Link>
72 </div>
73 <hr />
74 <div style={{ height: '200vh' }} />
75 <Link
76 preload="viewport"
77 to="/viewport-test"
78 activeProps={{
79 className: 'font-bold',
80 }}
81 >
82 viewport-test
83 </Link>
84 <Outlet />
85 {/* Start rendering router matches */}
86 <TanStackRouterDevtools position="bottom-right" />
87 </>
88 )