File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,11 @@ export interface RouterLinkProps extends RouterLinkOptions {
83
83
| 'time'
84
84
| 'true'
85
85
| 'false'
86
+
87
+ /**
88
+ * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
89
+ */
90
+ viewTransition ?: boolean
86
91
}
87
92
88
93
/**
@@ -106,7 +111,13 @@ export interface UseLinkOptions<Name extends keyof RouteMap = keyof RouteMap> {
106
111
| RouteLocationAsPath
107
112
| RouteLocationRaw
108
113
>
114
+
109
115
replace ?: MaybeRef < boolean | undefined >
116
+
117
+ /**
118
+ * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
119
+ */
120
+ viewTransition ?: boolean
110
121
}
111
122
112
123
/**
@@ -214,10 +225,19 @@ export function useLink<Name extends keyof RouteMap = keyof RouteMap>(
214
225
e : MouseEvent = { } as MouseEvent
215
226
) : Promise < void | NavigationFailure > {
216
227
if ( guardEvent ( e ) ) {
217
- return router [ unref ( props . replace ) ? 'replace' : 'push' ] (
228
+ const p = router [ unref ( props . replace ) ? 'replace' : 'push' ] (
218
229
unref ( props . to )
219
230
// avoid uncaught errors are they are logged anyway
220
231
) . catch ( noop )
232
+ if (
233
+ props . viewTransition &&
234
+ typeof document !== 'undefined' &&
235
+ 'startViewTransition' in document
236
+ ) {
237
+ // @ts -expect-error: not added to types yet
238
+ document . startViewTransition ( ( ) => p )
239
+ }
240
+ return p
221
241
}
222
242
return Promise . resolve ( )
223
243
}
You can’t perform that action at this time.
0 commit comments