]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(link): catch errors
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Jun 2021 22:02:28 +0000 (00:02 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Jun 2021 22:02:28 +0000 (00:02 +0200)
src/RouterLink.ts

index aef8e176a200bb99b6a31d037e627189128ae835..dbee6205bcf3985f6d5cc6cdfa68f1a2df80d076 100644 (file)
@@ -17,7 +17,7 @@ import { isSameRouteLocationParams, isSameRouteRecord } from './location'
 import { routerKey, routeLocationKey } from './injectionSymbols'
 import { RouteRecord } from './matcher/types'
 import { NavigationFailure } from './errors'
-import { isBrowser } from './utils'
+import { isBrowser, noop } from './utils'
 
 export interface RouterLinkOptions {
   /**
@@ -113,8 +113,12 @@ export function useLink(props: UseLinkOptions) {
   function navigate(
     e: MouseEvent = {} as MouseEvent
   ): Promise<void | NavigationFailure> {
-    if (guardEvent(e))
-      return router[unref(props.replace) ? 'replace' : 'push'](unref(props.to))
+    if (guardEvent(e)) {
+      return router[unref(props.replace) ? 'replace' : 'push'](
+        unref(props.to)
+        // avoid uncaught errors are they are logged anyway
+      ).catch(noop)
+    }
     return Promise.resolve()
   }