Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Migrate dynamic routing example to typescript #39806

Merged
merged 3 commits into from Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 0 additions & 30 deletions examples/dynamic-routing/components/header.js

This file was deleted.

30 changes: 30 additions & 0 deletions examples/dynamic-routing/components/header.tsx
@@ -0,0 +1,30 @@
import Link from 'next/link'

export default function Header() {
return (
<header>
<ul>
<li>
<Link href="/">
<a>Home</a>
</Link>
</li>
<li>
<Link href="/about">
<a>About</a>
</Link>
</li>
<li>
<Link href="/post/first">
<a>First Post</a>
</Link>
</li>
<li>
<Link href="/post/second">
<a>Second Post</a>
</Link>
</li>
</ul>
</header>
)
}
11 changes: 8 additions & 3 deletions examples/dynamic-routing/package.json
Expand Up @@ -6,8 +6,13 @@
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"next": "12.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "18.7.9",
"@types/react": "18.0.17",
"typescript": "4.7.4"
}
}
10 changes: 0 additions & 10 deletions examples/dynamic-routing/pages/about.js

This file was deleted.

10 changes: 10 additions & 0 deletions examples/dynamic-routing/pages/about.tsx
@@ -0,0 +1,10 @@
import Header from '../components/header'

export default function AboutPage() {
return (
<>
<Header />
<h1>About page</h1>
</>
)
}
10 changes: 0 additions & 10 deletions examples/dynamic-routing/pages/index.js

This file was deleted.

10 changes: 10 additions & 0 deletions examples/dynamic-routing/pages/index.tsx
@@ -0,0 +1,10 @@
import Header from '../components/header'

export default function IndexPage() {
return (
<>
<Header />
<h1>Hello World!</h1>
</>
)
}
@@ -1,9 +1,10 @@
import { useRouter } from 'next/router'
import Header from '../../../components/header'

const Comment = () => {
export default function CommentPage() {
const router = useRouter()
const { id, comment } = router.query
const id = router.query.id as string
const comment = router.query.comment as string

return (
<>
Expand All @@ -13,5 +14,3 @@ const Comment = () => {
</>
)
}

export default Comment
Expand Up @@ -2,28 +2,26 @@ import { useRouter } from 'next/router'
import Link from 'next/link'
import Header from '../../../components/header'

const Post = () => {
export default function PostPage() {
const router = useRouter()
const { id } = router.query
const id = router.query.id as string

return (
<>
<Header />
<h1>Post: {id}</h1>
<ul>
<li>
<Link href="/post/[id]/[comment]" as={`/post/${id}/first-comment`}>
<Link href={`/post/${id}/first-comment`}>
<a>First comment</a>
</Link>
</li>
<li>
<Link href="/post/[id]/[comment]" as={`/post/${id}/second-comment`}>
<Link href={`/post/${id}/second-comment`}>
<a>Second comment</a>
</Link>
</li>
</ul>
</>
)
}

export default Post
20 changes: 20 additions & 0 deletions examples/dynamic-routing/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}