Skip to content

Commit

Permalink
fix(react-server): decode dynamic route params (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 7, 2024
1 parent 660ca39 commit 6f5b90c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/react-server/examples/basic/e2e/basic.test.ts
Expand Up @@ -727,6 +727,14 @@ test("dynamic routes", async ({ page }) => {
await page.getByText("file: /test/dynamic/[id]/[nested]/page.tsx").click();
await page.getByText("pathname: /test/dynamic/abc/def").click();
await page.getByText('params: {"id":"abc","nested":"def"}').click();

await page.getByRole("link", { name: "/test/dynamic/๐ŸŽธ + ๐ŸŽท = ๐ŸŽถ" }).click();
await page.getByText('params: {"id":"๐ŸŽธ + ๐ŸŽท = ๐ŸŽถ"}').click();
await page.waitForURL("/test/dynamic/๐ŸŽธ + ๐ŸŽท = ๐ŸŽถ");

await page.getByRole("link", { name: "/test/dynamic/%F0%9F%8E%B8%" }).click();
await page.getByText('params: {"id":"๐ŸŽธ + ๐ŸŽท = ๐ŸŽถ"}').click();
await page.waitForURL("/test/dynamic/๐ŸŽธ + ๐ŸŽท = ๐ŸŽถ");
});

test("full client route", async ({ page }) => {
Expand Down
Expand Up @@ -11,6 +11,8 @@ export default function Layout(props: LayoutProps) {
"/test/dynamic",
"/test/dynamic/static",
"/test/dynamic/abc",
"/test/dynamic/๐ŸŽธ + ๐ŸŽท = ๐ŸŽถ",
"/test/dynamic/" + encodeURI("๐ŸŽธ + ๐ŸŽท = ๐ŸŽถ"),
"/test/dynamic/abc/def",
]}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/lib/router.tsx
Expand Up @@ -106,7 +106,7 @@ export async function renderRouteMap(
if (next?.child) {
node = next.child;
if (next.param) {
params = { ...params, [next.param]: key };
params = { ...params, [next.param]: decodeURI(key) };
}
} else {
node = initNode();
Expand Down

0 comments on commit 6f5b90c

Please sign in to comment.