File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 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 {
8383 | 'time'
8484 | 'true'
8585 | 'false'
86+
87+ /**
88+ * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
89+ */
90+ viewTransition ?: boolean
8691}
8792
8893/**
@@ -106,7 +111,13 @@ export interface UseLinkOptions<Name extends keyof RouteMap = keyof RouteMap> {
106111 | RouteLocationAsPath
107112 | RouteLocationRaw
108113 >
114+
109115 replace ?: MaybeRef < boolean | undefined >
116+
117+ /**
118+ * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
119+ */
120+ viewTransition ?: boolean
110121}
111122
112123/**
@@ -214,10 +225,19 @@ export function useLink<Name extends keyof RouteMap = keyof RouteMap>(
214225 e : MouseEvent = { } as MouseEvent
215226 ) : Promise < void | NavigationFailure > {
216227 if ( guardEvent ( e ) ) {
217- return router [ unref ( props . replace ) ? 'replace' : 'push' ] (
228+ const p = router [ unref ( props . replace ) ? 'replace' : 'push' ] (
218229 unref ( props . to )
219230 // avoid uncaught errors are they are logged anyway
220231 ) . 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
221241 }
222242 return Promise . resolve ( )
223243 }
You can’t perform that action at this time.
0 commit comments