@@ -17,6 +17,31 @@ const postRoute = createFileRoute('/_postLayout/posts/$postId_')()
1717
1818const protectedRoute = createFileRoute ( '/(auth)/protected' ) ( )
1919
20+ const attachmentRoute = createFileRoute (
21+ '/projects/$observationDocId/attachments/$driveId/$type/$variant/$name' ,
22+ ) ( {
23+ params : {
24+ parse : ( { driveId, type, variant, name, ...rest } ) => {
25+ const blobId =
26+ type === 'audio'
27+ ? {
28+ type : 'audio' as const ,
29+ variant : 'original' as const ,
30+ driveId,
31+ name,
32+ }
33+ : {
34+ type : 'photo' as const ,
35+ variant : variant as 'original' | 'preview' | 'thumbnail' ,
36+ driveId,
37+ name,
38+ }
39+
40+ return { ...rest , ...blobId }
41+ } ,
42+ } ,
43+ } )
44+
2045declare module '@tanstack/router-core' {
2146 interface FileRoutesByPath {
2247 '/' : {
@@ -68,6 +93,13 @@ declare module '@tanstack/router-core' {
6893 fullPath : '/posts/$postId'
6994 path : '/$postId_'
7095 }
96+ '/projects/$observationDocId/attachments/$driveId/$type/$variant/$name' : {
97+ preLoaderRoute : typeof attachmentRoute
98+ parentRoute : typeof rootRoute
99+ id : '/projects/$observationDocId/attachments/$driveId/$type/$variant/$name'
100+ fullPath : '/projects/$observationDocId/attachments/$driveId/$type/$variant/$name'
101+ path : '/projects/$observationDocId/attachments/$driveId/$type/$variant/$name'
102+ }
71103 }
72104}
73105
@@ -100,3 +132,31 @@ test('when creating a folder group', () => {
100132 expectTypeOf < '(auth)/protected' > ( protectedRoute . path )
101133 expectTypeOf < '/protected' > ( protectedRoute . id )
102134} )
135+
136+ test ( 'when file route params.parse returns a discriminated union' , ( ) => {
137+ expectTypeOf ( attachmentRoute . types . params ) . toEqualTypeOf <
138+ | {
139+ observationDocId : string
140+ driveId : string
141+ type : 'audio'
142+ variant : 'original'
143+ name : string
144+ }
145+ | {
146+ observationDocId : string
147+ driveId : string
148+ type : 'photo'
149+ variant : 'original' | 'preview' | 'thumbnail'
150+ name : string
151+ }
152+ > ( )
153+ } )
154+
155+ test ( 'when file route params.parse drops a path param' , ( ) => {
156+ createFileRoute ( '/invoices/$invoiceId' ) ( {
157+ params : {
158+ // @ts -expect-error parsed params must keep path param keys
159+ parse : ( ) => ( { } ) ,
160+ } ,
161+ } )
162+ } )
0 commit comments