You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/01-routing/04-linking-and-navigating.mdx
-115Lines changed: 0 additions & 115 deletions
Original file line number
Diff line number
Diff line change
@@ -40,121 +40,6 @@ export default function Page() {
40
40
41
41
There are other optional props you can pass to `<Link>`. See the [API reference](/docs/app/api-reference/components/link) for more.
42
42
43
-
### Examples
44
-
45
-
#### Linking to Dynamic Segments
46
-
47
-
When linking to [dynamic segments](/docs/app/building-your-application/routing/dynamic-routes), you can use [template literals and interpolation](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Template_literals) to generate a list of links. For example, to generate a list of blog posts:
You can use [`usePathname()`](/docs/app/api-reference/functions/use-pathname) to determine if a link is active. For example, to add a class to the active link, you can check if the current `pathname` matches the `href` of the link:
The default behavior of the Next.js App Router is to **scroll to the top of a new route or to maintain the scroll position for backwards and forwards navigation.**
124
-
125
-
If you'd like to scroll to a specific `id` on navigation, you can append your URL with a `#` hash link or just pass a hash link to the `href` prop. This is possible since `<Link>` renders to an `<a>` element.
126
-
127
-
```jsx
128
-
<Link href="/dashboard#settings">Settings</Link>
129
-
130
-
// Output
131
-
<a href="/dashboard#settings">Settings</a>
132
-
```
133
-
134
-
> **Good to know**:
135
-
>
136
-
> - Next.js will scroll to the [Page](/docs/app/building-your-application/routing/pages) if it is not visible in the viewport upon navigation.
137
-
138
-
#### Disabling scroll restoration
139
-
140
-
The default behavior of the Next.js App Router is to **scroll to the top of a new route or to maintain the scroll position for backwards and forwards navigation.** If you'd like to disable this behavior, you can pass `scroll={false}` to the `<Link>` component, or `scroll: false` to `router.push()` or `router.replace()`.
141
-
142
-
```jsx
143
-
// next/link
144
-
<Link href="/dashboard" scroll={false}>
145
-
Dashboard
146
-
</Link>
147
-
```
148
-
149
-
```jsx
150
-
// useRouter
151
-
import { useRouter } from'next/navigation'
152
-
153
-
constrouter=useRouter()
154
-
155
-
router.push('/dashboard', { scroll:false })
156
-
```
157
-
158
43
## `useRouter()` hook
159
44
160
45
The `useRouter` hook allows you to programmatically change routes from [Client Components](/docs/app/building-your-application/rendering/client-components).
0 commit comments