Skip to content

Commit 4f54803

Browse files
committedJan 30, 2025·
docs: scrollRestoration default and replace deprecated <ScrollRestoration>
1 parent abf9f05 commit 4f54803

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed
 

‎docs/router/framework/react/guide/tanstack-start.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ import { hydrateRoot } from 'react-dom/client'
183183
import { StartClient } from '@tanstack/start'
184184
import { createRouter } from './router'
185185

186-
const router = createRouter()
186+
const router = createRouter({ scrollRestoration: true })
187187

188188
hydrateRoot(document!, <StartClient router={router} />)
189189
```
@@ -197,7 +197,7 @@ Finally, we need to create the root of our application. This is the entry point
197197
```tsx
198198
// app/routes/__root.tsx
199199
import { createRootRoute } from '@tanstack/react-router'
200-
import { Outlet, ScrollRestoration } from '@tanstack/react-router'
200+
import { Outlet } from '@tanstack/react-router'
201201
import { Meta, Scripts } from '@tanstack/start'
202202
import * as React from 'react'
203203

@@ -233,7 +233,6 @@ function RootDocument({ children }: { children: React.ReactNode }) {
233233
</head>
234234
<body>
235235
{children}
236-
<ScrollRestoration />
237236
<Scripts />
238237
</body>
239238
</html>

‎docs/start/framework/react/build-from-scratch.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ import { hydrateRoot } from 'react-dom/client'
190190
import { StartClient } from '@tanstack/start'
191191
import { createRouter } from './router'
192192

193-
const router = createRouter()
193+
const router = createRouter({ scrollRestoration: true })
194194

195195
hydrateRoot(document, <StartClient router={router} />)
196196
```
@@ -203,11 +203,7 @@ Finally, we need to create the root of our application. This is the entry point
203203

204204
```tsx
205205
// app/routes/__root.tsx
206-
import {
207-
Outlet,
208-
ScrollRestoration,
209-
createRootRoute,
210-
} from '@tanstack/react-router'
206+
import { Outlet, createRootRoute } from '@tanstack/react-router'
211207
import { Meta, Scripts } from '@tanstack/start'
212208
import type { ReactNode } from 'react'
213209

@@ -245,7 +241,6 @@ function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
245241
</head>
246242
<body>
247243
{children}
248-
<ScrollRestoration />
249244
<Scripts />
250245
</body>
251246
</html>

‎docs/start/framework/react/learn-the-basics.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { routeTree } from './routeTree.gen'
2828
export function createRouter() {
2929
const router = createTanStackRouter({
3030
routeTree,
31+
scrollRestoration: true,
3132
})
3233

3334
return router
@@ -40,6 +41,8 @@ declare module '@tanstack/react-router' {
4041
}
4142
```
4243

44+
- Notice the `scrollRestoration` property. This is used to restore the scroll position of the page when navigating between routes.
45+
4346
## Route Generation
4447

4548
The `routeTree.gen.ts` file is generated when you run TanStack Start (via `npm run dev` or `npm run start`) for the first time. This file contains the generated route tree and a handful of TS utilities that make TanStack Start fully type-safe.
@@ -97,11 +100,7 @@ Because it is **always rendered**, it is the perfect place to construct your app
97100

98101
```tsx
99102
// app/routes/__root.tsx
100-
import {
101-
Outlet,
102-
ScrollRestoration,
103-
createRootRoute,
104-
} from '@tanstack/react-router'
103+
import { Outlet, createRootRoute } from '@tanstack/react-router'
105104
import { Meta, Scripts } from '@tanstack/start'
106105
import type { ReactNode } from 'react'
107106

@@ -139,7 +138,6 @@ function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
139138
</head>
140139
<body>
141140
{children}
142-
<ScrollRestoration />
143141
<Scripts />
144142
</body>
145143
</html>
@@ -148,7 +146,6 @@ function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
148146
```
149147

150148
- This layout may change in the future as we roll out SPA mode, which allows the root route to render the SPA shell without any page-specific content.
151-
- Notice the `ScrollRestoration` component. This is used to restore the scroll position of the page when navigating between routes.
152149
- Notice the `Scripts` component. This is used to load all of the client-side JavaScript for the application.
153150

154151
## Routes

‎packages/react-router/src/router.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ export interface RouterOptions<
459459
defaultRemountDeps?: (opts: MakeRemountDepsOptionsUnion<TRouteTree>) => any
460460

461461
/**
462-
* If `false`, scroll restoration will be disabled
462+
* If `true`, scroll restoration will be enabled
463463
*
464-
* @default true
464+
* @default false
465465
*/
466466
scrollRestoration?: boolean
467467
getScrollRestorationKey?: (location: ParsedLocation) => string

0 commit comments

Comments
 (0)
Please sign in to comment.