Skip to content

Commit ffd7cba

Browse files
yinonburganskyatilafassinabirkskyum
authored
fix: nested route with escaping resolved incorrectly (#1829) (#1834)
Co-authored-by: Atila Fassina <[email protected]> Co-authored-by: Birk Skyum <[email protected]>
1 parent 75581e0 commit ffd7cba

File tree

7 files changed

+43
-2
lines changed

7 files changed

+43
-2
lines changed

.changeset/young-shrimps-fetch.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@solidjs/start": patch
3+
---
4+
5+
fix nested route with escaping resolved incorrectly (#1829).
6+
before `/routes/nested/(ignored)route.tsx` resolved to `/nestedroute`
7+
now it resolves to `/nested/route`.

packages/start/src/router/routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function defineRoutes(fileRoutes: Route[]) {
3636
routes.push({
3737
...route,
3838
id,
39-
path: id.replace(/\/\([^)/]+\)/g, "").replace(/\([^)/]+\)/g, "")
39+
path: id.replace(/\([^)/]+\)/g, "").replace(/\/+/g, "/")
4040
});
4141
return routes;
4242
}
@@ -85,8 +85,8 @@ const router = createRouter({
8585
routes: (fileRoutes as unknown as Route[]).reduce((memo, route) => {
8686
if (!containsHTTP(route)) return memo;
8787
let path = route.path
88-
.replace(/\/\([^)/]+\)/g, "")
8988
.replace(/\([^)/]+\)/g, "")
89+
.replace(/\/+/g, "/")
9090
.replace(/\*([^/]*)/g, (_, m) => `**:${m}`)
9191
.split("/")
9292
.map(s => (s.startsWith(":") || s.startsWith("*") ? s : encodeURIComponent(s)))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
describe("route-groups", () => {
2+
it("should resolve `/routes/nested/(ignored)route0.tsx` to `nested/route0`", () => {
3+
cy.visit("/nested/route0");
4+
cy.contains("nested route 0")
5+
});
6+
it("should resolve `/routes/nested/(level1)/(ignored)route1.tsx` to `nested/route1`", () => {
7+
cy.visit("/nested/route1");
8+
cy.contains("nested route 1")
9+
});
10+
it("should resolve `/routes/nested/(level1)/(level2)/(ignored)route2.tsx` to `nested/route2`", () => {
11+
cy.visit("/nested/route2");
12+
cy.contains("nested route 2")
13+
});
14+
it("should resolve `/routes/nested/(level1)/(level2)/route3.tsx` to `nested/route3`", () => {
15+
cy.visit("/nested/route3");
16+
cy.contains("nested route 3")
17+
});
18+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export default function nested() {
3+
return <h1>nested route 0</h1>;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export default function nested() {
3+
return <h1>nested route 1</h1>;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export default function nested() {
3+
return <h1>nested route 2</h1>;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export default function nested() {
3+
return <h1>nested route 3</h1>;
4+
}

0 commit comments

Comments
 (0)