Skip to content

Commit 2b52abe

Browse files
fix: parent param types in server routes
fixes #5212
1 parent 6cc67e5 commit 2b52abe

File tree

5 files changed

+140
-29
lines changed

5 files changed

+140
-29
lines changed

e2e/react-start/server-routes/src/routeTree.gen.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { Route as rootRouteImport } from './routes/__root'
1212
import { Route as MergeServerFnMiddlewareContextRouteImport } from './routes/merge-server-fn-middleware-context'
1313
import { Route as IndexRouteImport } from './routes/index'
1414
import { Route as ApiMiddlewareContextRouteImport } from './routes/api/middleware-context'
15+
import { Route as ApiParamsFooRouteRouteImport } from './routes/api/params/$foo/route'
16+
import { Route as ApiParamsFooBarRouteImport } from './routes/api/params/$foo/$bar'
1517

1618
const MergeServerFnMiddlewareContextRoute =
1719
MergeServerFnMiddlewareContextRouteImport.update({
@@ -29,42 +31,68 @@ const ApiMiddlewareContextRoute = ApiMiddlewareContextRouteImport.update({
2931
path: '/api/middleware-context',
3032
getParentRoute: () => rootRouteImport,
3133
} as any)
34+
const ApiParamsFooRouteRoute = ApiParamsFooRouteRouteImport.update({
35+
id: '/api/params/$foo',
36+
path: '/api/params/$foo',
37+
getParentRoute: () => rootRouteImport,
38+
} as any)
39+
const ApiParamsFooBarRoute = ApiParamsFooBarRouteImport.update({
40+
id: '/$bar',
41+
path: '/$bar',
42+
getParentRoute: () => ApiParamsFooRouteRoute,
43+
} as any)
3244

3345
export interface FileRoutesByFullPath {
3446
'/': typeof IndexRoute
3547
'/merge-server-fn-middleware-context': typeof MergeServerFnMiddlewareContextRoute
3648
'/api/middleware-context': typeof ApiMiddlewareContextRoute
49+
'/api/params/$foo': typeof ApiParamsFooRouteRouteWithChildren
50+
'/api/params/$foo/$bar': typeof ApiParamsFooBarRoute
3751
}
3852
export interface FileRoutesByTo {
3953
'/': typeof IndexRoute
4054
'/merge-server-fn-middleware-context': typeof MergeServerFnMiddlewareContextRoute
4155
'/api/middleware-context': typeof ApiMiddlewareContextRoute
56+
'/api/params/$foo': typeof ApiParamsFooRouteRouteWithChildren
57+
'/api/params/$foo/$bar': typeof ApiParamsFooBarRoute
4258
}
4359
export interface FileRoutesById {
4460
__root__: typeof rootRouteImport
4561
'/': typeof IndexRoute
4662
'/merge-server-fn-middleware-context': typeof MergeServerFnMiddlewareContextRoute
4763
'/api/middleware-context': typeof ApiMiddlewareContextRoute
64+
'/api/params/$foo': typeof ApiParamsFooRouteRouteWithChildren
65+
'/api/params/$foo/$bar': typeof ApiParamsFooBarRoute
4866
}
4967
export interface FileRouteTypes {
5068
fileRoutesByFullPath: FileRoutesByFullPath
5169
fullPaths:
5270
| '/'
5371
| '/merge-server-fn-middleware-context'
5472
| '/api/middleware-context'
73+
| '/api/params/$foo'
74+
| '/api/params/$foo/$bar'
5575
fileRoutesByTo: FileRoutesByTo
56-
to: '/' | '/merge-server-fn-middleware-context' | '/api/middleware-context'
76+
to:
77+
| '/'
78+
| '/merge-server-fn-middleware-context'
79+
| '/api/middleware-context'
80+
| '/api/params/$foo'
81+
| '/api/params/$foo/$bar'
5782
id:
5883
| '__root__'
5984
| '/'
6085
| '/merge-server-fn-middleware-context'
6186
| '/api/middleware-context'
87+
| '/api/params/$foo'
88+
| '/api/params/$foo/$bar'
6289
fileRoutesById: FileRoutesById
6390
}
6491
export interface RootRouteChildren {
6592
IndexRoute: typeof IndexRoute
6693
MergeServerFnMiddlewareContextRoute: typeof MergeServerFnMiddlewareContextRoute
6794
ApiMiddlewareContextRoute: typeof ApiMiddlewareContextRoute
95+
ApiParamsFooRouteRoute: typeof ApiParamsFooRouteRouteWithChildren
6896
}
6997

7098
declare module '@tanstack/react-router' {
@@ -90,13 +118,39 @@ declare module '@tanstack/react-router' {
90118
preLoaderRoute: typeof ApiMiddlewareContextRouteImport
91119
parentRoute: typeof rootRouteImport
92120
}
121+
'/api/params/$foo': {
122+
id: '/api/params/$foo'
123+
path: '/api/params/$foo'
124+
fullPath: '/api/params/$foo'
125+
preLoaderRoute: typeof ApiParamsFooRouteRouteImport
126+
parentRoute: typeof rootRouteImport
127+
}
128+
'/api/params/$foo/$bar': {
129+
id: '/api/params/$foo/$bar'
130+
path: '/$bar'
131+
fullPath: '/api/params/$foo/$bar'
132+
preLoaderRoute: typeof ApiParamsFooBarRouteImport
133+
parentRoute: typeof ApiParamsFooRouteRoute
134+
}
93135
}
94136
}
95137

138+
interface ApiParamsFooRouteRouteChildren {
139+
ApiParamsFooBarRoute: typeof ApiParamsFooBarRoute
140+
}
141+
142+
const ApiParamsFooRouteRouteChildren: ApiParamsFooRouteRouteChildren = {
143+
ApiParamsFooBarRoute: ApiParamsFooBarRoute,
144+
}
145+
146+
const ApiParamsFooRouteRouteWithChildren =
147+
ApiParamsFooRouteRoute._addFileChildren(ApiParamsFooRouteRouteChildren)
148+
96149
const rootRouteChildren: RootRouteChildren = {
97150
IndexRoute: IndexRoute,
98151
MergeServerFnMiddlewareContextRoute: MergeServerFnMiddlewareContextRoute,
99152
ApiMiddlewareContextRoute: ApiMiddlewareContextRoute,
153+
ApiParamsFooRouteRoute: ApiParamsFooRouteRouteWithChildren,
100154
}
101155
export const routeTree = rootRouteImport
102156
._addFileChildren(rootRouteChildren)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/api/params/$foo/$bar')({
4+
server: {
5+
handlers: {
6+
GET: ({ params }) => {
7+
return new Response('hello, ' + params.foo + ' and ' + params.bar)
8+
},
9+
},
10+
},
11+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/api/params/$foo')({
4+
server: {
5+
handlers: {
6+
GET: ({ params }) => {
7+
return new Response('hello, ' + params.foo)
8+
},
9+
},
10+
},
11+
})

0 commit comments

Comments
 (0)