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

default.tsx

28 lines767 Bytes

1import { createFileRoute } from '@tanstack/solid-router'
2import { z } from 'zod'
3​
4export const Route = createFileRoute('/search-params/default')({
5 validateSearch: z.object({
6 default: z.string().default('d1'),
7 }),
8 beforeLoad: ({ context }) => {
9 if (context.hello !== 'world') {
10 throw new Error('Context hello is not "world"')
11 }
12 },
13 loader: ({ context }) => {
14 if (context.hello !== 'world') {
15 throw new Error('Context hello is not "world"')
16 }
17 },
18 component: () => {
19 const search = Route.useSearch()
20 const context = Route.useRouteContext()
21 return (
22 <>
23 <div data-testid="search-default">{search().default}</div>
24 <div data-testid="context-hello">{context().hello}</div>
25 </>
26 )
27 },
28})