add params, query to test

This commit is contained in:
tyage
2022-10-06 18:35:49 +09:00
parent 06925681b0
commit 1f4fc7fc2d
2 changed files with 17 additions and 25 deletions

View File

@@ -0,0 +1,17 @@
export default function Post({ id, q }) {
return (
<>
<div dangerouslySetInnerHTML={{__html: id }} />
<div dangerouslySetInnerHTML={{__html: q }} />
</>
)
}
export async function getServerSideProps(context) {
return {
props: {
id: context.params?.id || "",
q: context.query?.foobar || "",
}
}
}

View File

@@ -1,25 +0,0 @@
import type { GetServerSidePropsContext, GetStaticProps, GetStaticPropsContext, InferGetServerSidePropsType, InferGetStaticPropsType, NextPage } from 'next'
type Props = InferGetServerSidePropsType<typeof getServerSideProps>
const Home: NextPage<Props> = ({ id, url }) => {
return (
<>
<div dangerouslySetInnerHTML={{__html: url }} />
<div dangerouslySetInnerHTML={{__html: id }} />
</>
)
}
export function getServerSideProps(context: GetServerSidePropsContext<{ id: string, url: string }>) {
return {
props: {
id: context.params?.id,
url: decodeURIComponent(context.req.url || "")
}
}
}
export default Home