Open History to see the last commit
1import { expectTypeOf, test } from 'vitest'
2import { createFileRoute, createRootRoute } from '../src'
3β
4const rootRoute = createRootRoute()
5β
6const indexRoute = createFileRoute('/')()
7β
8const invoicesRoute = createFileRoute('/invoices')()
9β
10const invoiceRoute = createFileRoute('/invoices/$invoiceId')()
11β
12const postLayoutRoute = createFileRoute('/_postLayout')()
13β
14const postsRoute = createFileRoute('/_postLayout/posts')()
15β
16const postRoute = createFileRoute('/_postLayout/posts/$postId_')()
17β
18const protectedRoute = createFileRoute('/(auth)/protected')()
19β
20declare module '@tanstack/router-core' {
21 interface FileRoutesByPath {
22 '/': {
23 preLoaderRoute: typeof indexRoute
24 parentRoute: typeof rootRoute
25 id: string
26 fullPath: string
27 path: string
28 }
29 '/(auth)/protected': {
30 preLoaderRoute: typeof protectedRoute
31 parentRoute: typeof rootRoute
32 id: '/protected'
33 fullPath: '/protected'
34 path: '(auth)/protected'
35 }
36 '/invoices': {
37 preLoaderRoute: typeof invoicesRoute
38 parentRoute: typeof indexRoute
39 id: '/invoices'
40 fullPath: '/invoices'
41 path: 'invoices'
42 }
43 '/invoices/$invoiceId': {
44 preLoaderRoute: typeof invoiceRoute
45 parentRoute: typeof invoicesRoute
46 id: '/invoices/$invoiceId'
47 fullPath: '/invoices/$invoiceId'
48 path: '/$invoiceId'
49 }
50 '/_postLayout': {
51 preLoaderRoute: typeof postLayoutRoute
52 parentRoute: typeof rootRoute
53 id: string
54 fullPath: string
55 path: string
56 }
57 '/_postLayout/posts': {
58 preLoaderRoute: typeof postsRoute
59 parentRoute: typeof postLayoutRoute
60 id: '/_postLayout/posts'
61 fullPath: '/posts'
62 path: '/posts'
63 }
64 '/_postLayout/posts/$postId_': {
65 preLoaderRoute: typeof postRoute
66 parentRoute: typeof postsRoute
67 id: '/_postLayout/posts/$postId_'
68 fullPath: '/posts/$postId'
69 path: '/$postId_'
70 }
71 }
72}
73β
74test('when creating a file route with a static route', () => {
75 expectTypeOf<'/invoices'>(invoicesRoute.fullPath)
76 expectTypeOf<'/invoices'>(invoicesRoute.id)
77 expectTypeOf<'invoices'>(invoicesRoute.path)
78})
79β
80test('when creating a file route with params', () => {
81 expectTypeOf<'/invoices/$invoiceId'>(invoiceRoute.fullPath)
82 expectTypeOf<'/invoices/$invoiceId'>(invoiceRoute.id)
83 expectTypeOf<'/$invoiceId'>(invoiceRoute.path)
84})
85β
86test('when creating a layout route', () => {
87 expectTypeOf<'/posts'>(postsRoute.fullPath)
88 expectTypeOf<'/_postLayout/posts'>(postsRoute.id)
89 expectTypeOf<'/posts'>(postsRoute.path)
90})
91β
92test('when creating a _ suffix route', () => {
93 expectTypeOf<'/posts/$postId'>(postRoute.fullPath)
94 expectTypeOf<'/$postId_'>(postRoute.path)
95 expectTypeOf<'/_postLayout/posts/$postId_'>(postRoute.id)
96})
97β
98test('when creating a folder group', () => {
99 expectTypeOf<'/protected'>(protectedRoute.fullPath)
100 expectTypeOf<'(auth)/protected'>(protectedRoute.path)
101 expectTypeOf<'/protected'>(protectedRoute.id)
102})