File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import router from './router';
44import store from './store' ;
55
66import { Component } from 'vue-property-decorator' ;
7+ import { Route } from 'vue-router' ;
78
89Component . registerHooks ( [
910 'beforeRouteEnter' ,
@@ -13,6 +14,10 @@ Component.registerHooks([
1314
1415Vue . config . productionTip = false ;
1516
17+ router . beforeEach ( ( to : Route , from : Route , next : ( ) => void ) => {
18+ console . log ( to , from ) ;
19+ next ( ) ;
20+ } ) ;
1621new Vue ( {
1722 router,
1823 store,
Original file line number Diff line number Diff line change 11<template >
22 <div class =" about" >
33 <h1 >This is an about page</h1 >
4+ <button @click =" goBack" >go back</button >
45 </div >
56</template >
67
@@ -17,7 +18,7 @@ export default class About extends Vue {
1718
1819 private beforeRouteEnter(to : Route , from : Route , next : () => void ): void {
1920 console .log (' beforeRouteEnter' , to , from , next );
20- next (); // 没有next将不会进入路由内部,跟vue文档用法一致
21+ next ();
2122 }
2223
2324 private beforeRouteUpdate(to : Route , from : Route , next : () => void ): void {
@@ -29,6 +30,10 @@ export default class About extends Vue {
2930 console .log (' beforeRouteLeave' );
3031 next ();
3132 }
33+
34+ private goBack() {
35+ this .$router .back ();
36+ }
3237}
3338
3439 </script >
You can’t perform that action at this time.
0 commit comments