add test for context.params

This commit is contained in:
tyage
2022-10-06 18:09:06 +09:00
parent 1e8b4bdd6f
commit 06925681b0
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
{
"name": "my-app",
"version": "0.1.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^10.0.0",
"react": "17.0.1",
"react-dom": "17.0.1"
}
}

View File

@@ -0,0 +1,25 @@
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