Skip to content

Commit 16b42b0

Browse files
internal routing update
1 parent 29a68bc commit 16b42b0

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

pages/docs/[[...params]].js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useRouter } from 'next/router'
2+
3+
function Doc() {
4+
const router = useRouter()
5+
const { params = [] } = router.query
6+
console.log(params)
7+
8+
if (params.length === 2) {
9+
return (
10+
<h1>
11+
Viewing docs for feature {params[0]} and concept {params[1]}
12+
</h1>
13+
)
14+
} else if (params.length === 1) {
15+
return <h1>Viewing docs for feature {params[0]}</h1>
16+
}
17+
18+
return <h1>Docs Home Page</h1>
19+
}
20+
21+
export default Doc

pages/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import Link from 'next/link'
2+
13
function Home() {
2-
return <h1>Home Page</h1>;
4+
return (
5+
<>
6+
<h1>Home Page</h1>
7+
<Link href='/blog'>
8+
<a>Blog</a>
9+
</Link>
10+
<Link href='/product'>
11+
<a>Products</a>
12+
</Link>
13+
</>
14+
)
315
}
416

5-
export default Home;
17+
export default Home

pages/product/index.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1-
function ProductList() {
1+
// Use the Link component to navigate to different routes
2+
// For internal routes, you only need to use an /PAGE href. For external routes, you still use a typical HTML href
3+
import Link from 'next/link'
4+
5+
function ProductList({ productId = 4 }) {
26
return (
37
<>
4-
<h2>Product 1</h2>
5-
<h2>Product 2</h2>
6-
<h2>Product 3</h2>
8+
<Link href='/'>
9+
<a>Home</a>
10+
</Link>
11+
<h2>
12+
<Link href='/product/1'>
13+
<a>Product 1</a>
14+
</Link>
15+
</h2>
16+
<h2>
17+
<Link href='/product/2'>
18+
<a>Product 2</a>
19+
</Link>
20+
</h2>
21+
<h2>
22+
<Link href='/product/3'>
23+
<a>Product 3</a>
24+
</Link>
25+
</h2>
26+
<h2>
27+
<Link href={`/product/${productId}`}>
28+
<a>Product {productId}</a>
29+
</Link>
30+
</h2>
731
</>
832
)
933
}

0 commit comments

Comments
 (0)