]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
types(guards): allow to return values in guards
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 21 Jul 2020 13:03:09 +0000 (15:03 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 21 Jul 2020 13:03:09 +0000 (15:03 +0200)
src/types/index.ts

index 88e15635540810d09cbd1a1eea839c1b8fc9c96e..cb8138f4a640364380a1916fb5f456e4219c8ba1 100644 (file)
@@ -278,13 +278,20 @@ export interface NavigationGuardNext {
 
 export type NavigationGuardNextCallback = (vm: ComponentPublicInstance) => any
 
+export type NavigationGuardReturn =
+  | void
+  | Error
+  | RouteLocationRaw
+  | boolean
+  | NavigationGuardNextCallback
+
 export interface NavigationGuard {
   (
     // TODO: we could maybe add extra information like replace: true/false
     to: RouteLocationNormalized,
     from: RouteLocationNormalized,
     next: NavigationGuardNext
-  ): any
+  ): NavigationGuardReturn | Promise<NavigationGuardReturn>
 }
 
 export interface NavigationGuardWithThis<T> {
@@ -293,7 +300,7 @@ export interface NavigationGuardWithThis<T> {
     to: RouteLocationNormalized,
     from: RouteLocationNormalized,
     next: NavigationGuardNext
-  ): any
+  ): NavigationGuardReturn | Promise<NavigationGuardReturn>
 }
 
 export interface PostNavigationGuard {