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

__root.tsx

62 lines1.4 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 // @ts-expect-error
48 to="/this-route-does-not-exist"
49 activeProps={{
50 className: 'font-bold',
51 }}
52 >
53 This Route Does Not Exist
54 </Link>
55 </div>
56 <hr />
57 <Outlet />
58 {/* Start rendering router matches */}
59 <TanStackRouterDevtools position="bottom-right" />
60 </>
61 )