Skip to content

Commit 839e114

Browse files
authored
fix(router): decode path for storing elements and slug as prop (#1304)
Let me know if this approach is ok. The change makes it so that id's internally for routes are always decoded. This makes it so the prop is decoded when it is passed. It also fixes the runtime error. The runtime error happened when the id as being looked up in elements as decoded, but internally stored as encoded, so our invalid element id error was thrown. fixes #1302 --------- Co-authored-by: Tyler <[email protected]>
1 parent 2cd6b1b commit 839e114

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

e2e/create-pages.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ for (const mode of ['DEV', 'PRD'] as const) {
6767
).toBeVisible();
6868
});
6969

70+
test("nested/cat's pajamas", async ({ page }) => {
71+
await page.goto(`http://localhost:${port}/nested/cat's%20pajamas`);
72+
await expect(
73+
page.getByRole('heading', { name: "Dynamic: cat's pajamas" }),
74+
).toBeVisible();
75+
});
76+
7077
test('jump', async ({ page }) => {
7178
await page.goto(`http://localhost:${port}`);
7279
await page.click("a[href='/foo']");

packages/waku/src/router/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class CustomErrorHandler extends Component<
430430
}
431431
}
432432

433-
const getRouteSlotId = (path: string) => 'route:' + path;
433+
const getRouteSlotId = (path: string) => 'route:' + decodeURIComponent(path);
434434

435435
const handleScroll = () => {
436436
const { hash } = window.location;

packages/waku/src/router/define-router.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,12 @@ export function unstable_defineRouter(fns: {
243243
if (!pathConfigItem.specs.rootElementIsStatic || !skipIdSet.has('root')) {
244244
entries.root = rootElement;
245245
}
246-
const routeId = ROUTE_SLOT_ID_PREFIX + pathname;
246+
const decodedPathname = decodeURIComponent(pathname);
247+
const routeId = ROUTE_SLOT_ID_PREFIX + decodedPathname;
247248
if (!pathConfigItem.specs.routeElementIsStatic || !skipIdSet.has(routeId)) {
248249
entries[routeId] = routeElement;
249250
}
250-
entries[ROUTE_ID] = [pathname, query];
251+
entries[ROUTE_ID] = [decodedPathname, query];
251252
entries[IS_STATIC_ID] = !!pathConfigItem.specs.isStatic;
252253
if (await has404()) {
253254
entries[HAS404_ID] = true;

0 commit comments

Comments
 (0)