Skip to content

Commit e44c976

Browse files
docs(how-to/view-transitions): add programmatic navigation example (#13627)
* docs(view-transitions): add programmatic navigation example and update section numbering * Add matteogauthier to contributor
1 parent 45fa820 commit e44c976

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
- mathpaquette
225225
- matmilbury
226226
- matt-harro
227+
- matteogauthier
227228
- matthewlynch
228229
- maximevtush
229230
- maxpou

docs/how-to/view-transitions.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,35 @@ The simplest way to enable view transitions is by adding the `viewTransition` pr
2020

2121
Without any additional CSS, this provides a basic cross-fade animation between pages.
2222

23+
### 2. Enable view transitions with programmatic navigation
24+
25+
When using programmatic navigation with the `useNavigate` hook, you can enable view transitions by passing the `viewTransition: true` option:
26+
27+
```tsx
28+
import { useNavigate } from "react-router";
29+
30+
function NavigationButton() {
31+
const navigate = useNavigate();
32+
33+
return (
34+
<button
35+
onClick={() => navigate("/about", { viewTransition: true })}
36+
>
37+
About
38+
</button>
39+
);
40+
}
41+
```
42+
43+
This provides the same cross-fade animation as using the `viewTransition` prop on Link components.
44+
2345
For more information on using the View Transitions API, please refer to the ["Smooth transitions with the View Transition API" guide][view-transitions-guide] from the Google Chrome team.
2446

2547
## Image Gallery Example
2648

2749
Let's build an image gallery that demonstrates how to trigger and use view transitions. We'll create a list of images that expand into a detail view with smooth animations.
2850

29-
### 2. Create the image gallery route
51+
### 1. Create the image gallery route
3052

3153
```tsx filename=routes/image-gallery.tsx
3254
import { NavLink } from "react-router";
@@ -62,7 +84,7 @@ export default function ImageGalleryRoute() {
6284
}
6385
```
6486

65-
### 3. Add transition styles
87+
### 2. Add transition styles
6688

6789
Define view transition names and animations for elements that should transition smoothly between routes.
6890

@@ -98,7 +120,7 @@ Define view transition names and animations for elements that should transition
98120
}
99121
```
100122

101-
### 4. Create the image detail route
123+
### 3. Create the image detail route
102124

103125
The detail view needs to use the same view transition names to create a seamless animation.
104126

@@ -122,7 +144,7 @@ export default function ImageDetailsRoute({
122144
}
123145
```
124146

125-
### 5. Add matching transition styles for the detail view
147+
### 4. Add matching transition styles for the detail view
126148

127149
```css filename=app.css
128150
/* Match transition names from the list view */

0 commit comments

Comments
 (0)