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 { 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="/route-a"
40 activeProps={{
41 className: 'font-bold',
42 }}
43 >
44 Pathless Layout
45 </Link>{' '}
46 <Link
47 to="/anchor"
48 activeProps={{
49 className: 'font-bold',
50 }}
51 >
52 Anchor
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 {/* Start rendering router matches */}
67 <TanStackRouterDevtools position="bottom-right" />
68 </>
69 )