mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What?
Adds `useParams` to read the canonical parameters.
```tsx
'use client'
import { useParams } from 'next/navigation'
export default function Page() {
const { id } = useParams()
return (
<div>
<div id="param-id">{id}</div>
</div>
)
}
```
### Why?
Allows for accessing segment parameters for the entire page.
### How?
It uses a similar resolving of `useSelectedLayoutSegments` which resolve `children` and if `children` is not available the first available parallel route instead.
Closes NEXT-99
19 lines
285 B
TypeScript
19 lines
285 B
TypeScript
import Link from 'next/link'
|
|
|
|
export default function Page() {
|
|
return (
|
|
<>
|
|
<div>
|
|
<Link href="/a" id="to-a">
|
|
To /a
|
|
</Link>
|
|
</div>
|
|
<div>
|
|
<Link href="/a/b" id="to-a-b">
|
|
To /a/b
|
|
</Link>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|