Skip to content

Commit bb1c72d

Browse files
authored
fix: extra slash in path (#156)
1 parent 9782364 commit bb1c72d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function buildHelpers(config: RequiredReactRouterConfig): Promise<[RoutesI
3939
} else {
4040
currentPath = [...currentPath, route];
4141
const fullPath = dedupPrefixSlash(currentPath.reduce(
42-
(acc, curr) => [acc, trimSlash(curr.path)].filter(p => p != undefined).join('/'),
42+
(acc, curr) => "/" + [acc, trimSlash(curr.path)].filter(Boolean).join('/'),
4343
'',
4444
));
4545
const paramsNames = parse(currentPath);

tests/__snapshots__/build.test.ts.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ exports[`gen route types 1`] = `
7777
params: never,
7878
query: ExportedQuery<import('../app/routes/credits.js').SearchParams>,
7979
},
80+
"/fruits": {
81+
params: never,
82+
query: ExportedQuery<import('../app/routes/fruits/index/route.js').SearchParams>,
83+
},
84+
"/fruits/:id": {
85+
params: {'id': string | number},
86+
query: ExportedQuery<import('../app/routes/fruits/show/route.js').SearchParams>,
87+
},
8088
"/home": {
8189
params: never,
8290
query: ExportedQuery<import('../app/routes/(static).home.js').SearchParams>,
@@ -171,6 +179,9 @@ exports[`gen route types 1`] = `
171179
| 'routes/blog._index'
172180
| 'routes/auth.$provider-key'
173181
| 'routes/($provider-key).about'
182+
| 'routes/fruits/route'
183+
| 'routes/fruits/index/route'
184+
| 'routes/fruits/show/route'
174185
| 'catchall';
175186
176187
export function $path<

tests/fixture.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ export const testRoutes =
196196
path: ":provider-key?/about",
197197
parentId: "root",
198198
},
199+
"routes/fruits/route": {
200+
file: "routes/fruits/route.tsx",
201+
id: "routes/fruits/route",
202+
path: "fruits",
203+
parentId: "root",
204+
},
205+
"routes/fruits/index/route": {
206+
file: "routes/fruits/index/route.tsx",
207+
id: "routes/fruits/index/route",
208+
path: "",
209+
parentId: "routes/fruits/route",
210+
},
211+
"routes/fruits/show/route": {
212+
file: "routes/fruits/show/route.tsx",
213+
id: "routes/fruits/show/route",
214+
path: ":id",
215+
parentId: "routes/fruits/index/route",
216+
},
199217
catchall: {
200218
path: "/somewhere/cool/*",
201219
index: undefined,

0 commit comments

Comments
 (0)