Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/nx-20.4-broke-lazy-loading-import-detection
Browse files Browse the repository at this point in the history
SeanCassiere authored Jan 30, 2025
2 parents 5327a21 + 830dafe commit 17619ee
Showing 328 changed files with 2,103 additions and 920 deletions.
110 changes: 0 additions & 110 deletions docs/config.json → docs/router/config.json
Original file line number Diff line number Diff line change
@@ -184,77 +184,6 @@
}
]
},
{
"label": "Start",
"children": [],
"frameworks": [
{
"label": "react",
"children": [
{
"label": "Overview",
"to": "framework/react/start/overview"
},
{
"label": "Getting Started",
"to": "framework/react/start/getting-started"
},
{
"label": "Quick Start",
"to": "framework/react/start/quick-start"
},
{
"label": "Build from Scratch",
"to": "framework/react/start/build-from-scratch"
},
{
"label": "Learn the Basics",
"to": "framework/react/start/learn-the-basics"
},
{
"label": "Server Functions",
"to": "framework/react/start/server-functions"
},
{
"label": "Middleware",
"to": "framework/react/start/middleware"
},
{
"label": "API Routes",
"to": "framework/react/start/api-routes"
},
{
"label": "SSR",
"to": "framework/react/start/ssr"
},
{
"label": "Hosting",
"to": "framework/react/start/hosting"
},
{
"label": "Authentication",
"to": "framework/react/start/authentication"
},
{
"label": "Databases",
"to": "framework/react/start/databases"
},
{
"label": "Observability",
"to": "framework/react/start/observability"
},
{
"label": "Static Prerendering",
"to": "framework/react/start/static-prerendering"
},
{
"label": "Path Aliases",
"to": "framework/react/start/path-aliases"
}
]
}
]
},
{
"label": "API",
"children": [],
@@ -381,45 +310,6 @@
]
}
]
},
{
"label": "Start Examples",
"children": [],
"frameworks": [
{
"label": "react",
"children": [
{
"label": "Basic",
"to": "framework/react/examples/start-basic"
},
{
"label": "Basic + React Query",
"to": "framework/react/examples/start-basic-react-query"
},
{
"label": "Basic + Clerk Auth",
"to": "framework/react/examples/start-clerk-basic"
},
{
"label": "Basic + DIY Auth",
"to": "framework/react/examples/start-basic-auth"
},
{
"label": "Basic + Supabase Auth",
"to": "framework/react/examples/start-supabase-basic"
},
{
"label": "Trellaux + Convex",
"to": "framework/react/examples/start-convex-trellaux"
},
{
"label": "Trellaux",
"to": "framework/react/examples/start-trellaux"
}
]
}
]
}
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -9,39 +9,48 @@ The `RouterEvents` type contains all of the events that the router can emit. Eac
type RouterEvents = {
onBeforeNavigate: {
type: 'onBeforeNavigate'
fromLocation: ParsedLocation
fromLocation?: ParsedLocation
toLocation: ParsedLocation
pathChanged: boolean
hrefChanged: boolean
}
onBeforeLoad: {
type: 'onBeforeLoad'
fromLocation: ParsedLocation
fromLocation?: ParsedLocation
toLocation: ParsedLocation
pathChanged: boolean
hrefChanged: boolean
}
onLoad: {
type: 'onLoad'
fromLocation: ParsedLocation
fromLocation?: ParsedLocation
toLocation: ParsedLocation
pathChanged: boolean
hrefChanged: boolean
}
onResolved: {
type: 'onResolved'
fromLocation: ParsedLocation
fromLocation?: ParsedLocation
toLocation: ParsedLocation
pathChanged: boolean
hrefChanged: boolean
}
onBeforeRouteMount: {
type: 'onBeforeRouteMount'
fromLocation: ParsedLocation
fromLocation?: ParsedLocation
toLocation: ParsedLocation
pathChanged: boolean
hrefChanged: boolean
}
onInjectedHtml: {
type: 'onInjectedHtml'
promise: Promise<string>
}
onRendered: {
type: 'onRendered'
fromLocation?: ParsedLocation
toLocation: ParsedLocation
}
}
```
Original file line number Diff line number Diff line change
@@ -57,6 +57,8 @@ Feature/Capability Key:
| `<Block>`/`useBlocker` || 🔶 ||
| Deferred Primitives ||||
| Navigation Scroll Restoration ||||
| ElementScroll Restoration || 🛑 | 🛑 |
| Async Scroll Restoration || 🛑 | 🛑 |
| Router Invalidation ||||
| Runtime Route Manipulation (Fog of War) | 🛑 |||
| -- | -- | -- | -- |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -3,6 +3,12 @@ id: scroll-restoration
title: Scroll Restoration
---

## Hash/Top-of-Page Scrolling

Out of the box, TanStack Router supports both **hash scrolling** and **top-of-page scrolling** without any additional configuration.

## Scroll Restoration

Scroll restoration is the process of restoring the scroll position of a page when the user navigates back to it. This is normally a built-in feature for standard HTML based websites, but can be difficult to replicate for SPA applications because:

- SPAs typically use the `history.pushState` API for navigation, so the browser doesn't know to restore the scroll position natively
@@ -24,19 +30,15 @@ It does this by:
That may sound like a lot, but for you, it's as simple as this:

```tsx
import { ScrollRestoration } from '@tanstack/react-router'
import { createRouter } from '@tanstack/react-router'

function Root() {
return (
<>
<ScrollRestoration />
<Outlet />
</>
)
}
const router = createRouter({
scrollRestoration: true,
})
```

Just render the `ScrollRestoration` component (or use the `useScrollRestoration` hook) at the root of your application and it will handle everything automatically!
> [!NOTE]
> The `<ScrollRestoration />` component still works, but has been deprecated.
## Custom Cache Keys

@@ -51,38 +53,26 @@ The default `getKey` is `(location) => location.state.key!`, where `key` is the
You could sync scrolling to the pathname:

```tsx
import { ScrollRestoration } from '@tanstack/react-router'
import { createRouter } from '@tanstack/react-router'

function Root() {
return (
<>
<ScrollRestoration getKey={(location) => location.pathname} />
<Outlet />
</>
)
}
const router = createRouter({
getScrollRestorationKey: (location) => location.pathname,
})
```

You can conditionally sync only some paths, then use the key for the rest:

```tsx
import { ScrollRestoration } from '@tanstack/react-router'

function Root() {
return (
<>
<ScrollRestoration
getKey={(location) => {
const paths = ['/', '/chat']
return paths.includes(location.pathname)
? location.pathname
: location.state.key!
}}
/>
<Outlet />
</>
)
}
import { createRouter } from '@tanstack/react-router'

const router = createRouter({
getScrollRestorationKey: (location) => {
const paths = ['/', '/chat']
return paths.includes(location.pathname)
? location.pathname
: location.state.key!
},
})
```

## Preventing Scroll Restoration
@@ -143,14 +133,9 @@ function Component() {
To control the scroll behavior when navigating between pages, you can use the `scrollBehavior` option. This allows you to make the transition between pages instant instead of a smooth scroll. The global configuration of scroll restoration behavior has the same options as those supported by the browser, which are `smooth`, `instant`, and `auto` (see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#behavior) for more information).

```tsx
import { ScrollRestoration } from '@tanstack/react-router'
import { createRouter } from '@tanstack/react-router'

function Root() {
return (
<>
<ScrollRestoration scrollBehavior="instant" />
<Outlet />
</>
)
}
const router = createRouter({
scrollBehavior: 'instant',
})
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 17619ee

Please sign in to comment.