File tree 2 files changed +11
-1
lines changed
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';
4
4
import store from './store' ;
5
5
6
6
import { Component } from 'vue-property-decorator' ;
7
+ import { Route } from 'vue-router' ;
7
8
8
9
Component . registerHooks ( [
9
10
'beforeRouteEnter' ,
@@ -13,6 +14,10 @@ Component.registerHooks([
13
14
14
15
Vue . config . productionTip = false ;
15
16
17
+ router . beforeEach ( ( to : Route , from : Route , next : ( ) => void ) => {
18
+ console . log ( to , from ) ;
19
+ next ( ) ;
20
+ } ) ;
16
21
new Vue ( {
17
22
router,
18
23
store,
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div class =" about" >
3
3
<h1 >This is an about page</h1 >
4
+ <button @click =" goBack" >go back</button >
4
5
</div >
5
6
</template >
6
7
@@ -17,7 +18,7 @@ export default class About extends Vue {
17
18
18
19
private beforeRouteEnter(to : Route , from : Route , next : () => void ): void {
19
20
console .log (' beforeRouteEnter' , to , from , next );
20
- next (); // 没有next将不会进入路由内部,跟vue文档用法一致
21
+ next ();
21
22
}
22
23
23
24
private beforeRouteUpdate(to : Route , from : Route , next : () => void ): void {
@@ -29,6 +30,10 @@ export default class About extends Vue {
29
30
console .log (' beforeRouteLeave' );
30
31
next ();
31
32
}
33
+
34
+ private goBack() {
35
+ this .$router .back ();
36
+ }
32
37
}
33
38
34
39
</script >
You can’t perform that action at this time.
0 commit comments