Skip to content

Commit 7a55d7d

Browse files
joseinaqaautofix-ci[bot]schiller-manuel
authored
fix(router-core): allow to return false to skip navigation using view transition types (#5492)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Manuel Schiller <manuel.schiller@caligano.de>
1 parent 6a2ca0b commit 7a55d7d

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

docs/router/framework/react/api/router/NavigateOptionsType.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The `NavigateOptions` object accepts the following properties:
5050
- Optional
5151
- Defaults to `false`.
5252
- If `true`, navigation will be called using `document.startViewTransition()`.
53-
- If [`ViewTransitionOptions`](../ViewTransitionOptionsType.md), route navigations will be called using `document.startViewTransition({update, types})` where `types` will be the strings array passed with `ViewTransitionOptions["types"]`. If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.
53+
- If [`ViewTransitionOptions`](../ViewTransitionOptionsType.md), route navigations will be called using `document.startViewTransition({update, types})` where `types` will determine the strings array passed with `ViewTransitionOptions["types"]`. If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.
5454
- If the browser does not support this api, this option will be ignored.
5555
- See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works.
5656
- See [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types) for more information on viewTransition types

docs/router/framework/react/api/router/ViewTransitionOptionsType.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ The `ViewTransitionOptions` type is used to define a
88

99
```tsx
1010
interface ViewTransitionOptions {
11-
types: Array<string>
11+
types: Array<string> | ((locationChangeInfo: {
12+
fromLocation?: ParsedLocation
13+
toLocation: ParsedLocation
14+
pathChanged: boolean
15+
hrefChanged: boolean
16+
hashChanged: boolean
17+
}) => (Array<string> | false))
1218
}
1319
```
1420

@@ -18,6 +24,16 @@ The `ViewTransitionOptions` type accepts an object with a single property:
1824

1925
### `types` property
2026

21-
- Type: `Array<string>`
27+
- Type: `Array<string> | ((locationChangeInfo: {
28+
fromLocation?: ParsedLocation
29+
toLocation: ParsedLocation
30+
pathChanged: boolean
31+
hrefChanged: boolean
32+
hashChanged: boolean
33+
}) => (Array<string> | false))`
2234
- Required
23-
- The types array that will be passed to the `document.startViewTransition({update, types}) call`;
35+
- Either one of:
36+
- An array of strings that will be passed to the `document.startViewTransition({update, types}) call`
37+
- A function that accepts `locationChangeInfo` object and returns either:
38+
- An array of strings that will be passed to the `document.startViewTransition({update, types}) call`
39+
- or `false` to skip the view transition

packages/router-core/src/router.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ export interface ViewTransitionOptions {
774774
pathChanged: boolean
775775
hrefChanged: boolean
776776
hashChanged: boolean
777-
}) => Array<string>)
777+
}) => Array<string> | false)
778778
}
779779

780780
// TODO where is this used? can we remove this?
@@ -2175,6 +2175,11 @@ export class RouterCore<
21752175
)
21762176
: shouldViewTransition.types
21772177

2178+
if (resolvedViewTransitionTypes === false) {
2179+
fn()
2180+
return
2181+
}
2182+
21782183
startViewTransitionParams = {
21792184
update: fn,
21802185
types: resolvedViewTransitionTypes,

0 commit comments

Comments
 (0)