fix: main index not found in group (#1710)

This commit is contained in:
Marvin Hagemeister
2023-09-05 12:16:19 +02:00
committed by GitHub
parent c767cc5067
commit ac5e4c5ca1
7 changed files with 64 additions and 0 deletions
+5
View File
@@ -1183,6 +1183,11 @@ export function pathToPattern(path: string): string {
route += "/" + pattern;
}
// Case: /(group)/index.tsx
if (route === "") {
route = "/";
}
return route;
}
+13
View File
@@ -0,0 +1,13 @@
{
"lock": false,
"imports": {
"$fresh/": "../../",
"preact": "https://esm.sh/preact@10.15.1",
"preact/": "https://esm.sh/preact@10.15.1/",
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env -S deno run -A --watch=static/,routes/
import dev from "$fresh/dev.ts";
await dev(import.meta.url, "./main.ts");
+15
View File
@@ -0,0 +1,15 @@
// DO NOT EDIT. This file is generated by Fresh.
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.
import * as $0 from "./routes/(group)/index.tsx";
const manifest = {
routes: {
"./routes/(group)/index.tsx": $0,
},
islands: {},
baseUrl: import.meta.url,
};
export default manifest;
+10
View File
@@ -0,0 +1,10 @@
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
await start(manifest);
@@ -0,0 +1,3 @@
export default function Page() {
return <h1>it works</h1>;
}
+13
View File
@@ -2,6 +2,7 @@ import { assertEquals } from "$std/testing/asserts.ts";
import {
assertTextMany,
fetchHtml,
parseHtml,
waitForText,
withFresh,
withPageName,
@@ -71,3 +72,15 @@ Deno.test("does not treat files in (_...) as routes", async () => {
},
);
});
Deno.test("resolve index route in group /(group)/index.tsx", async () => {
await withFresh(
"./tests/fixture_group_index/main.ts",
async (address) => {
const res = await fetch(`${address}`);
assertEquals(res.status, 200);
const doc = parseHtml(await res.text());
assertEquals(doc.querySelector("h1")?.textContent, "it works");
},
);
});