Files
Tim NeutkensandGitHub f029023a3c Add useParams() (#47373)
### 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
2023-03-22 09:26:19 +00:00

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>
</>
)
}