fix: PluginRoute supports AsyncRoute and AsyncLayout (#2139)
This commit is contained in:
@@ -3,10 +3,12 @@ import { handler as testMiddleware } from "./sample_routes/_middleware.ts";
|
||||
import { AppBuilder } from "./sample_routes/AppBuilder.tsx";
|
||||
import IslandPluginComponent from "./sample_routes/PluginRouteWithIsland.tsx";
|
||||
import { SimpleRoute } from "./sample_routes/simple-route.tsx";
|
||||
import AsyncRoute from "./sample_routes/async-route.tsx";
|
||||
export type { Options };
|
||||
|
||||
interface Options {
|
||||
title: string;
|
||||
async: boolean;
|
||||
}
|
||||
export type PluginMiddlewareState = {
|
||||
num: number;
|
||||
@@ -45,6 +47,7 @@ export default function routePlugin(
|
||||
path: "lots-of-middleware",
|
||||
}],
|
||||
routes: [
|
||||
{ path: "/async-route", component: AsyncRoute },
|
||||
{
|
||||
path: "/_app",
|
||||
component: AppBuilder(options),
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
import { defineApp, PageProps } from "$fresh/server.ts";
|
||||
import { Head } from "../../../../runtime.ts";
|
||||
import { Options } from "../route-plugin.ts";
|
||||
|
||||
export function AppBuilder(options: Options) {
|
||||
return ({ Component }: PageProps) => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{options.title}</title>
|
||||
</Head>
|
||||
<main class="max-w-screen-md px-4 pt-16 mx-auto">
|
||||
<Component />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
return options.async
|
||||
? defineApp((_req, ctx) => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{options.title}</title>
|
||||
</Head>
|
||||
<main class="max-w-screen-md px-4 pt-16 mx-auto">
|
||||
foo
|
||||
<ctx.Component />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
})
|
||||
: ({ Component }: PageProps) => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{options.title}</title>
|
||||
</Head>
|
||||
<main class="max-w-screen-md px-4 pt-16 mx-auto">
|
||||
<Component />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { defineRoute } from "$fresh/src/server/defines.ts";
|
||||
|
||||
export default defineRoute((_req, _ctx) => {
|
||||
return (
|
||||
<div>
|
||||
this is an async route!
|
||||
</div>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user