feat: pass middleware state in props (#1264)
This commit is contained in:
@@ -32,9 +32,11 @@ import * as $26 from "./routes/middleware_root.ts";
|
||||
import * as $27 from "./routes/not_found.ts";
|
||||
import * as $28 from "./routes/params.tsx";
|
||||
import * as $29 from "./routes/props/[id].tsx";
|
||||
import * as $30 from "./routes/static.tsx";
|
||||
import * as $31 from "./routes/status_overwrite.tsx";
|
||||
import * as $32 from "./routes/wildcard.tsx";
|
||||
import * as $30 from "./routes/state-in-props/_middleware.ts";
|
||||
import * as $31 from "./routes/state-in-props/index.tsx";
|
||||
import * as $32 from "./routes/static.tsx";
|
||||
import * as $33 from "./routes/status_overwrite.tsx";
|
||||
import * as $34 from "./routes/wildcard.tsx";
|
||||
import * as $$0 from "./islands/Counter.tsx";
|
||||
import * as $$1 from "./islands/ReturningNull.tsx";
|
||||
import * as $$2 from "./islands/RootFragment.tsx";
|
||||
@@ -75,9 +77,11 @@ const manifest = {
|
||||
"./routes/not_found.ts": $27,
|
||||
"./routes/params.tsx": $28,
|
||||
"./routes/props/[id].tsx": $29,
|
||||
"./routes/static.tsx": $30,
|
||||
"./routes/status_overwrite.tsx": $31,
|
||||
"./routes/wildcard.tsx": $32,
|
||||
"./routes/state-in-props/_middleware.ts": $30,
|
||||
"./routes/state-in-props/index.tsx": $31,
|
||||
"./routes/static.tsx": $32,
|
||||
"./routes/status_overwrite.tsx": $33,
|
||||
"./routes/wildcard.tsx": $34,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$0,
|
||||
|
||||
@@ -2,10 +2,16 @@ import { Head } from "$fresh/runtime.ts";
|
||||
import { AppProps } from "$fresh/server.ts";
|
||||
|
||||
export default function App(props: AppProps) {
|
||||
const statefulValue = props.state?.root === "root_mw"
|
||||
? "The freshest framework!"
|
||||
: "";
|
||||
const specialCase = props.state?.stateInProps as string;
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<meta name="description" content="Hello world!" />
|
||||
<meta name="generator" content={statefulValue} />
|
||||
{specialCase && <meta name="specialTag" content={specialCase} />}
|
||||
</Head>
|
||||
<props.Component />
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext,
|
||||
) {
|
||||
ctx.state.stateInProps = "look, i am set from middleware";
|
||||
const resp = await ctx.next();
|
||||
return resp;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers<boolean> = {
|
||||
GET(_, ctx) {
|
||||
const complexValue = true;
|
||||
return ctx.render(complexValue);
|
||||
},
|
||||
};
|
||||
|
||||
export default function Page(props: PageProps<boolean>) {
|
||||
let valueFromState = props.state.stateInProps as string;
|
||||
if (props.data) {
|
||||
valueFromState = valueFromState.toUpperCase();
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<h1>{valueFromState}</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user