Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The `NavigateOptions` object accepts the following properties:
- Optional
- Defaults to `false`.
- If `true`, navigation will be called using `document.startViewTransition()`.
- 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.
- 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.
- If the browser does not support this api, this option will be ignored.
- See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works.
- See [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types) for more information on viewTransition types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ The `ViewTransitionOptions` type is used to define a

```tsx
interface ViewTransitionOptions {
types: Array<string>
types: Array<string> | ((locationChangeInfo: {
fromLocation?: ParsedLocation
toLocation: ParsedLocation
pathChanged: boolean
hrefChanged: boolean
hashChanged: boolean
}) => (Array<string> | false))
}
```

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

### `types` property

- Type: `Array<string>`
- Type: `Array<string> | ((locationChangeInfo: {
fromLocation?: ParsedLocation
toLocation: ParsedLocation
pathChanged: boolean
hrefChanged: boolean
hashChanged: boolean
}) => (Array<string> | false))`
- Required
- The types array that will be passed to the `document.startViewTransition({update, types}) call`;
- Either one of:
- An array of strings that will be passed to the `document.startViewTransition({update, types}) call`
- A function that accepts `locationChangeInfo` object and returns either:
- An array of strings that will be passed to the `document.startViewTransition({update, types}) call`
- or `false` to skip the view transition
7 changes: 6 additions & 1 deletion packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ export interface ViewTransitionOptions {
pathChanged: boolean
hrefChanged: boolean
hashChanged: boolean
}) => Array<string>)
}) => Array<string> | false)
}

// TODO where is this used? can we remove this?
Expand Down Expand Up @@ -2175,6 +2175,11 @@ export class RouterCore<
)
: shouldViewTransition.types

if (resolvedViewTransitionTypes === false) {
fn()
return
}

startViewTransitionParams = {
update: fn,
types: resolvedViewTransitionTypes,
Expand Down