Skip to content

Commit 0692568

Browse files
committed
add test for context.params
1 parent 1e8b4bd commit 0692568

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "my-app",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"dev": "next dev",
6+
"build": "next build",
7+
"start": "next start"
8+
},
9+
"dependencies": {
10+
"next": "^10.0.0",
11+
"react": "17.0.1",
12+
"react-dom": "17.0.1"
13+
}
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { GetServerSidePropsContext, GetStaticProps, GetStaticPropsContext, InferGetServerSidePropsType, InferGetStaticPropsType, NextPage } from 'next'
2+
3+
type Props = InferGetServerSidePropsType<typeof getServerSideProps>
4+
5+
const Home: NextPage<Props> = ({ id, url }) => {
6+
return (
7+
<>
8+
<div dangerouslySetInnerHTML={{__html: url }} />
9+
<div dangerouslySetInnerHTML={{__html: id }} />
10+
</>
11+
)
12+
}
13+
14+
15+
export function getServerSideProps(context: GetServerSidePropsContext<{ id: string, url: string }>) {
16+
return {
17+
props: {
18+
id: context.params?.id,
19+
url: decodeURIComponent(context.req.url || "")
20+
}
21+
}
22+
}
23+
24+
25+
export default Home

0 commit comments

Comments
 (0)