diff --git a/packages/void/test/integration/static-pages.test.ts b/packages/void/test/integration/static-pages.test.ts index 9b64db4f0..c37e2e35d 100644 --- a/packages/void/test/integration/static-pages.test.ts +++ b/packages/void/test/integration/static-pages.test.ts @@ -61,6 +61,18 @@ describe("playground/static-pages build (output: static)", () => { expect(html).not.toContain("/@id/"); }); + it("prerenders dynamic pages with getPrerenderPaths", () => { + // posts/[slug] exports getPrerenderPaths returning [{slug:"hello"},{slug:"world"}] + const helloPath = join(DIST, "client/posts/hello.html"); + const worldPath = join(DIST, "client/posts/world.html"); + expect(existsSync(helloPath)).toBe(true); + expect(existsSync(worldPath)).toBe(true); + + const html = readFileSync(helloPath, "utf-8"); + expect(html).toContain('data-testid="post-title"'); + expect(html).toContain("Post hello"); + }); + it("does not prerender dynamic pages without getPrerenderPaths", () => { // items/[id] has no getPrerenderPaths, so it should NOT be prerendered expect(existsSync(join(DIST, "client/items"))).toBe(false); diff --git a/playground/static-pages/pages/posts/[slug].server.ts b/playground/static-pages/pages/posts/[slug].server.ts new file mode 100644 index 000000000..69cc74fc2 --- /dev/null +++ b/playground/static-pages/pages/posts/[slug].server.ts @@ -0,0 +1,15 @@ +import { defineHandler } from "void"; + +export interface Props { + slug: string; +} + +export const prerender = true; + +export function getPrerenderPaths() { + return [{ slug: "hello" }, { slug: "world" }]; +} + +export const loader = defineHandler((c) => { + return { slug: c.req.param("slug") }; +}); diff --git a/playground/static-pages/pages/posts/[slug].vue b/playground/static-pages/pages/posts/[slug].vue new file mode 100644 index 000000000..e547f47fe --- /dev/null +++ b/playground/static-pages/pages/posts/[slug].vue @@ -0,0 +1,9 @@ + + +