Open History to see the last commit
1import {
2 HeadContent,
3 Link,
4 Outlet,
5 createRootRoute,
6 useCanGoBack,
7 useRouter,
8 useRouterState,
9} from '@tanstack/solid-router'
10import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
11β
12export const Route = createRootRoute({
13 component: RootComponent,
14 notFoundComponent: () => {
15 return (
16 <div>
17 <p>This is the notFoundComponent configured on root route</p>
18 <Link to="/">Start Over</Link>
19 </div>
20 )
21 },
22})
23β
24function RootComponent() {
25 const router = useRouter()
26 const canGoBack = useCanGoBack()
27 // test useRouterState doesn't crash client side navigation
28 const _state = useRouterState()
29β
30 return (
31 <>
32 <HeadContent />
33 <div class="flex gap-2 p-2 text-lg border-b">
34 <button
35 data-testid="back-button"
36 disabled={!canGoBack()}
37 onClick={() => router.history.back()}
38 class={!canGoBack() ? 'line-through' : undefined}
39 >
40 Back
41 </button>{' '}
42 <Link
43 to="/"
44 activeProps={{
45 class: 'font-bold',
46 }}
47 activeOptions={{ exact: true }}
48 >
49 Home
50 </Link>{' '}
51 <Link
52 to="/posts"
53 activeProps={{
54 class: 'font-bold',
55 }}
56 >
57 Posts
58 </Link>{' '}
59 <Link
60 to="/layout-a"
61 activeProps={{
62 class: 'font-bold',
63 }}
64 >
65 Layout
66 </Link>{' '}
67 <Link
68 to="/onlyrouteinside"
69 data-testid="link-to-only-route-inside-group"
70 search={{ hello: 'world' }}
71 activeProps={{
72 class: 'font-bold',
73 }}
74 >
75 Only Route Inside Group
76 </Link>{' '}
77 <Link
78 to="/inside"
79 data-testid="link-to-route-inside-group"
80 search={{ hello: 'world' }}
81 activeProps={{
82 class: 'font-bold',
83 }}
84 >
85 Inside Group
86 </Link>{' '}
87 <Link
88 to="/subfolder/inside"
89 data-testid="link-to-route-inside-group-inside-subfolder"
90 search={{ hello: 'world' }}
91 activeProps={{
92 class: 'font-bold',
93 }}
94 >
95 Inside Subfolder Inside Group
96 </Link>{' '}
97 <Link
98 to="/insidelayout"
99 data-testid="link-to-route-inside-group-inside-layout"
100 search={{ hello: 'world' }}
101 activeProps={{
102 class: 'font-bold',
103 }}
104 >
105 Inside Group Inside Layout
106 </Link>{' '}
107 <Link
108 to="/lazyinside"
109 data-testid="link-to-lazy-route-inside-group"
110 search={{ hello: 'world' }}
111 activeProps={{
112 class: 'font-bold',
113 }}
114 >
115 Lazy Inside Group
116 </Link>{' '}
117 <Link
118 to="/redirect"
119 activeProps={{
120 class: 'font-bold',
121 }}
122 >
123 redirect
124 </Link>{' '}
125 <Link
126 to="/relative"
127 activeProps={{
128 class: 'font-bold',
129 }}
130 >
131 relative routing
132 </Link>{' '}
133 <Link
134 to="/λνλ―Όκ΅"
135 activeProps={{
136 class: 'font-bold',
137 }}
138 >
139 unicode path
140 </Link>{' '}
141 <Link
142 // @ts-expect-error
143 to="/this-route-does-not-exist"
144 activeProps={{
145 class: 'font-bold',
146 }}
147 >
148 This Route Does Not Exist
149 </Link>{' '}
150 <Link
151 to="/masks"
152 data-testid="link-to-masks"
153 activeProps={{
154 class: 'font-bold',
155 }}
156 >
157 Masks
158 </Link>
159 </div>
160 <hr />
161 <Outlet />
162 {/* Start rendering router matches */}
163 <TanStackRouterDevtools position="bottom-right" />
164 </>
165 )
166}