fix: PageProps.params never contains arrays, only strings (#91)
This commit is contained in:
@@ -14,9 +14,9 @@ export interface PageProps<
|
||||
* For the `/foo/:bar` route with url `/foo/123`, `params` would be
|
||||
* `{ bar: '123' }`. For a route with no matchers, `params` would be `{}`. For
|
||||
* a wildcard route, like `/foo/:path*` with url `/foo/bar/baz`, `params` would
|
||||
* be `{ path: [ 'bar', 'baz' ] }`.
|
||||
* be `{ path: 'bar/baz' }`.
|
||||
*/
|
||||
params: Record<string, string | string[]>;
|
||||
params: Record<string, string>;
|
||||
|
||||
/**
|
||||
* Additional data passed into `HandlerContext.render`. Not present by
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/** @jsx h */
|
||||
|
||||
import { h, PageConfig, PageProps } from "../deps.ts";
|
||||
|
||||
export default function WildcardPage({ params }: PageProps) {
|
||||
if (typeof params.path === "string") {
|
||||
return <p>{params.path}</p>;
|
||||
} else {
|
||||
return <p>Not a string.</p>;
|
||||
}
|
||||
}
|
||||
|
||||
export const config: PageConfig = {
|
||||
routeOverride: "/foo/:path*",
|
||||
};
|
||||
+12
-10
@@ -10,11 +10,12 @@ import * as $4 from "./pages/props/[id].tsx";
|
||||
import * as $5 from "./pages/failure.ts";
|
||||
import * as $6 from "./pages/_middleware.ts";
|
||||
import * as $7 from "./pages/books/[id].tsx";
|
||||
import * as $8 from "./pages/api/get_only.ts";
|
||||
import * as $9 from "./pages/_500.tsx";
|
||||
import * as $10 from "./pages/intercept.tsx";
|
||||
import * as $11 from "./pages/_404.tsx";
|
||||
import * as $12 from "./pages/[name].tsx";
|
||||
import * as $8 from "./pages/wildcard.tsx";
|
||||
import * as $9 from "./pages/api/get_only.ts";
|
||||
import * as $10 from "./pages/_500.tsx";
|
||||
import * as $11 from "./pages/intercept.tsx";
|
||||
import * as $12 from "./pages/_404.tsx";
|
||||
import * as $13 from "./pages/[name].tsx";
|
||||
|
||||
const routes = {
|
||||
pages: {
|
||||
@@ -26,11 +27,12 @@ const routes = {
|
||||
"./pages/failure.ts": $5,
|
||||
"./pages/_middleware.ts": $6,
|
||||
"./pages/books/[id].tsx": $7,
|
||||
"./pages/api/get_only.ts": $8,
|
||||
"./pages/_500.tsx": $9,
|
||||
"./pages/intercept.tsx": $10,
|
||||
"./pages/_404.tsx": $11,
|
||||
"./pages/[name].tsx": $12,
|
||||
"./pages/wildcard.tsx": $8,
|
||||
"./pages/api/get_only.ts": $9,
|
||||
"./pages/_500.tsx": $10,
|
||||
"./pages/intercept.tsx": $11,
|
||||
"./pages/_404.tsx": $12,
|
||||
"./pages/[name].tsx": $13,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
+11
-3
@@ -39,20 +39,20 @@ Deno.test("/props/123 page prerender", async () => {
|
||||
});
|
||||
|
||||
Deno.test("/[name] page prerender", async () => {
|
||||
const resp = await router(new Request("https://fresh.deno.dev/foo"));
|
||||
const resp = await router(new Request("https://fresh.deno.dev/bar"));
|
||||
assert(resp);
|
||||
assertEquals(resp.status, 200);
|
||||
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||
const body = await resp.text();
|
||||
assertStringIncludes(body, "[name].js");
|
||||
assertStringIncludes(body, "<div>Hello foo</div>");
|
||||
assertStringIncludes(body, "<div>Hello bar</div>");
|
||||
assertStringIncludes(
|
||||
body,
|
||||
`<script id="__FRSH_PROPS" type="application/json">`,
|
||||
);
|
||||
assertStringIncludes(
|
||||
body,
|
||||
`"params":{"name":"foo"}`,
|
||||
`"params":{"name":"bar"}`,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -170,3 +170,11 @@ Deno.test("/failure", async () => {
|
||||
const body = await resp.text();
|
||||
assert(body.includes("500 internal error: it errored!"));
|
||||
});
|
||||
|
||||
Deno.test("/foo/:path*", async () => {
|
||||
const resp = await router(new Request("https://fresh.deno.dev/foo/bar/baz"));
|
||||
assert(resp);
|
||||
assertEquals(resp.status, 200);
|
||||
const body = await resp.text();
|
||||
assert(body.includes("bar/baz"));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user