feat: allow layout and _app overrides (#1611)
This commit is contained in:
@@ -23,9 +23,15 @@ import * as $17 from "./routes/foo/_layout.tsx";
|
||||
import * as $18 from "./routes/foo/bar.tsx";
|
||||
import * as $19 from "./routes/foo/index.tsx";
|
||||
import * as $20 from "./routes/index.tsx";
|
||||
import * as $21 from "./routes/other.tsx";
|
||||
import * as $22 from "./routes/skip/sub/_layout.tsx";
|
||||
import * as $23 from "./routes/skip/sub/index.tsx";
|
||||
import * as $21 from "./routes/no_app.tsx";
|
||||
import * as $22 from "./routes/other.tsx";
|
||||
import * as $23 from "./routes/override/_layout.tsx";
|
||||
import * as $24 from "./routes/override/index.tsx";
|
||||
import * as $25 from "./routes/override/no_app.tsx";
|
||||
import * as $26 from "./routes/override/no_layout.tsx";
|
||||
import * as $27 from "./routes/override/no_layout_no_app.tsx";
|
||||
import * as $28 from "./routes/skip/sub/_layout.tsx";
|
||||
import * as $29 from "./routes/skip/sub/index.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
@@ -50,9 +56,15 @@ const manifest = {
|
||||
"./routes/foo/bar.tsx": $18,
|
||||
"./routes/foo/index.tsx": $19,
|
||||
"./routes/index.tsx": $20,
|
||||
"./routes/other.tsx": $21,
|
||||
"./routes/skip/sub/_layout.tsx": $22,
|
||||
"./routes/skip/sub/index.tsx": $23,
|
||||
"./routes/no_app.tsx": $21,
|
||||
"./routes/other.tsx": $22,
|
||||
"./routes/override/_layout.tsx": $23,
|
||||
"./routes/override/index.tsx": $24,
|
||||
"./routes/override/no_app.tsx": $25,
|
||||
"./routes/override/no_layout.tsx": $26,
|
||||
"./routes/override/no_layout_no_app.tsx": $27,
|
||||
"./routes/skip/sub/_layout.tsx": $28,
|
||||
"./routes/skip/sub/index.tsx": $29,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { RouteConfig } from "$fresh/server.ts";
|
||||
|
||||
export const config: RouteConfig = {
|
||||
appTemplate: false,
|
||||
};
|
||||
|
||||
export default function OverridePage() {
|
||||
return (
|
||||
<html>
|
||||
<body>
|
||||
<p class="no-app">
|
||||
no <pre>_app.tsx</pre> template
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { LayoutProps, RouteConfig } from "$fresh/server.ts";
|
||||
|
||||
export const config: RouteConfig = {
|
||||
rootLayout: true,
|
||||
};
|
||||
|
||||
export default function OverrideLayout({ Component }: LayoutProps) {
|
||||
return (
|
||||
<div class="override-layout">
|
||||
<Component />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function OverridePage() {
|
||||
return (
|
||||
<div class="override-page">
|
||||
/override index page
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { RouteConfig } from "$fresh/server.ts";
|
||||
|
||||
export const config: RouteConfig = {
|
||||
appTemplate: false,
|
||||
};
|
||||
|
||||
export default function OverridePage() {
|
||||
return (
|
||||
<p class="no-app">
|
||||
no <code>_app.tsx</code> template
|
||||
</p>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { RouteConfig } from "$fresh/server.ts";
|
||||
|
||||
export const config: RouteConfig = {
|
||||
rootLayout: true,
|
||||
};
|
||||
|
||||
export default function OverridePage() {
|
||||
return (
|
||||
<p class="no-layouts">
|
||||
no layouts
|
||||
</p>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { RouteConfig } from "$fresh/server.ts";
|
||||
|
||||
export const config: RouteConfig = {
|
||||
appTemplate: false,
|
||||
rootLayout: true,
|
||||
};
|
||||
|
||||
export default function OverridePage() {
|
||||
return (
|
||||
<p class="no-app-no-layouts">
|
||||
no <code>_app.tsx</code> template and no layouts
|
||||
</p>
|
||||
);
|
||||
}
|
||||
+47
-1
@@ -1,5 +1,10 @@
|
||||
import { assert } from "./deps.ts";
|
||||
import { assertSelector, fetchHtml, withFresh } from "./test_utils.ts";
|
||||
import {
|
||||
assertNotSelector,
|
||||
assertSelector,
|
||||
fetchHtml,
|
||||
withFresh,
|
||||
} from "./test_utils.ts";
|
||||
|
||||
Deno.test("apply root _layout and _app", async () => {
|
||||
await withFresh(
|
||||
@@ -103,3 +108,44 @@ Deno.test({
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test("disable _app layout", async () => {
|
||||
await withFresh(
|
||||
"./tests/fixture_layouts/main.ts",
|
||||
async (address) => {
|
||||
const doc = await fetchHtml(`${address}/override/no_app`);
|
||||
assertNotSelector(doc, "body body");
|
||||
assertSelector(doc, "body > .override-layout >.no-app");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("override layouts", async () => {
|
||||
await withFresh(
|
||||
"./tests/fixture_layouts/main.ts",
|
||||
async (address) => {
|
||||
const doc = await fetchHtml(`${address}/override`);
|
||||
assertSelector(doc, "body > .app > .override-layout > .override-page");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("route overrides layout", async () => {
|
||||
await withFresh(
|
||||
"./tests/fixture_layouts/main.ts",
|
||||
async (address) => {
|
||||
const doc = await fetchHtml(`${address}/override/no_layout`);
|
||||
assertSelector(doc, "body > .app > .no-layouts");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("route overrides layout", async () => {
|
||||
await withFresh(
|
||||
"./tests/fixture_layouts/main.ts",
|
||||
async (address) => {
|
||||
const doc = await fetchHtml(`${address}/override/no_layout_no_app`);
|
||||
assertSelector(doc, "body > .no-app-no-layouts");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -40,6 +40,15 @@ export function assertSelector(doc: Document, selector: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function assertNotSelector(doc: Document, selector: string) {
|
||||
if (doc.querySelector(selector) !== null) {
|
||||
const html = prettyDom(doc);
|
||||
throw new Error(
|
||||
`Selector "${selector}" found in document.\n\n${html}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function assertTextMany(
|
||||
doc: Document,
|
||||
selector: string,
|
||||
|
||||
Reference in New Issue
Block a user