@@ -41,50 +41,59 @@ const state = reactive({
41
41
leave : 0 ,
42
42
} )
43
43
44
- const Foo = defineComponent ( {
45
- template : `
46
- <div>
47
- foo
48
- <p id="enterCbs">{{ enterCallback }}</p>
49
- <p id="update">{{ selfUpdates }}</p>
50
- <p id="leave">{{ selfLeaves }}</p>
44
+ /**
45
+ * creates a component that logs the guards
46
+ * @param name
47
+ */
48
+ function createTestComponent ( key : string ) {
49
+ return defineComponent ( {
50
+ template : `
51
+ <div :id="key">
52
+ {{ key }}
53
+ <p class="enterCbs">{{ enterCallback }}</p>
54
+ <p class="update">{{ selfUpdates }}</p>
55
+ <p class="leave">{{ selfLeaves }}</p>
51
56
</div>
52
57
` ,
53
- data : ( ) => ( { key : 'Foo' , enterCallback : 0 , selfUpdates : 0 , selfLeaves : 0 } ) ,
54
- // mounted() {
55
- // console.log('mounted Foo')
56
- // },
57
- beforeRouteEnter ( to , from , next ) {
58
- state . enter ++
59
- logs . value . push ( `enter ${ from . path } - ${ to . path } ` )
60
- next ( vm => {
61
- // @ts -ignore
62
- vm . enterCallback ++
63
- } )
64
- } ,
65
- beforeRouteUpdate ( to , from ) {
66
- if ( ! this || this . key !== 'Foo' ) throw new Error ( 'no this' )
67
- state . update ++
68
- this . selfUpdates ++
69
- logs . value . push ( `update ${ from . path } - ${ to . path } ` )
70
- } ,
71
- beforeRouteLeave ( to , from ) {
72
- if ( ! this || this . key !== 'Foo' ) throw new Error ( 'no this' )
73
- state . leave ++
74
- this . selfLeaves ++
75
- logs . value . push ( `leave ${ from . path } - ${ to . path } ` )
76
- } ,
58
+ data : ( ) => ( { key, enterCallback : 0 , selfUpdates : 0 , selfLeaves : 0 } ) ,
59
+ // mounted() {
60
+ // console.log('mounted Foo')
61
+ // },
62
+ beforeRouteEnter ( to , from , next ) {
63
+ state . enter ++
64
+ logs . value . push ( `${ key } : enter ${ from . path } - ${ to . path } ` )
65
+ next ( vm => {
66
+ // @ts -ignore
67
+ vm . enterCallback ++
68
+ } )
69
+ } ,
70
+ beforeRouteUpdate ( to , from ) {
71
+ if ( ! this || this . key !== key ) throw new Error ( 'no this' )
72
+ state . update ++
73
+ this . selfUpdates ++
74
+ logs . value . push ( `${ key } : update ${ from . path } - ${ to . path } ` )
75
+ } ,
76
+ beforeRouteLeave ( to , from ) {
77
+ if ( ! this || this . key !== key ) throw new Error ( 'no this' )
78
+ state . leave ++
79
+ this . selfLeaves ++
80
+ logs . value . push ( `${ key } : leave ${ from . path } - ${ to . path } ` )
81
+ } ,
77
82
78
- setup ( ) {
79
- onBeforeRouteUpdate ( ( to , from ) => {
80
- logs . value . push ( `setup:update ${ from . path } - ${ to . path } ` )
81
- } )
82
- onBeforeRouteLeave ( ( to , from ) => {
83
- logs . value . push ( `setup:leave ${ from . path } - ${ to . path } ` )
84
- } )
85
- return { }
86
- } ,
87
- } )
83
+ setup ( ) {
84
+ onBeforeRouteUpdate ( ( to , from ) => {
85
+ logs . value . push ( `${ key } : setup:update ${ from . path } - ${ to . path } ` )
86
+ } )
87
+ onBeforeRouteLeave ( ( to , from ) => {
88
+ logs . value . push ( `${ key } : setup:leave ${ from . path } - ${ to . path } ` )
89
+ } )
90
+ return { }
91
+ } ,
92
+ } )
93
+ }
94
+
95
+ const Foo = createTestComponent ( 'Foo' )
96
+ const Aux = createTestComponent ( 'Aux' )
88
97
89
98
const webHistory = createWebHistory ( '/' + __dirname )
90
99
const router = createRouter ( {
0 commit comments