]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
feat: prepare callback for NavigationGuardCallback
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 27 Sep 2019 08:20:27 +0000 (10:20 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 27 Sep 2019 08:20:27 +0000 (10:20 +0200)
explorations/html5.html
explorations/html5.ts
src/types/index.ts

index 18d096bc134780cc03307535039aeeea98fcf0cc..79b8c191a922ea37aea116147a8acc6efa6c14db 100644 (file)
@@ -85,6 +85,9 @@
         <!-- <li>
           <router-link :to="{ name: 'docs' }">Doc with same id</router-link>
         </li> -->
+        <li>
+          <router-link to="/with-data">/with-data</router-link>
+        </li>
       </ul>
       <transition
         name="fade"
index 68f35685080cb2295bfc6f8a424f5352bedd5bab..9358100661e5da91e0ff3f70c771612088c50dc8 100644 (file)
@@ -60,6 +60,23 @@ const GuardedWithLeave: RouteComponent = {
   },
 }
 
+const ComponentWithData: RouteComponent = {
+  template: `<div>
+    <p>Here is the data: {{ data }}</p>
+  </div>`,
+  // @ts-ignore
+  data: () => ({ data: 'nope' }),
+  beforeRouteEnter(to, from, next) {
+    console.log('this in beforeRouteEnter', this)
+    setTimeout(() => {
+      next(vm => {
+        console.log('got vm', vm)
+        vm.data = 'Hola'
+      })
+    }, 300)
+  },
+}
+
 if ('scrollRestoration' in history) {
   history.scrollRestoration = 'manual'
 }
@@ -118,6 +135,7 @@ const router = new Router({
         { path: 'b', name: 'b-child', component },
       ],
     },
+    { path: '/with-data', component: ComponentWithData, name: 'WithData' },
     // { path: /^\/about\/?$/, component },
   ],
   async scrollBehavior(to, from, savedPosition) {
index 782b57d84cb5c6cf4e09b92d6414df826b08b216..614794e78061df8a2a47e0e997e03058b29c2664 100644 (file)
@@ -182,6 +182,7 @@ export interface NavigationGuardCallback {
   (): void
   (location: RouteLocation): void
   (valid: false): void
+  (cb: (vm: any) => void): void
 }
 
 export interface NavigationGuard<V = void> {