@@ -17,7 +17,7 @@ import {
17
17
NavigationFailure ,
18
18
NavigationRedirectError ,
19
19
} from './errors'
20
- import { ComponentOptions } from 'vue'
20
+ import { ComponentOptions , onUnmounted } from 'vue'
21
21
import { inject , getCurrentInstance , warn } from 'vue'
22
22
import { matchedRouteKey } from './injectionSymbols'
23
23
import { RouteRecordNormalized } from './matcher/types'
@@ -49,10 +49,14 @@ export function onBeforeRouteLeave(leaveGuard: NavigationGuard) {
49
49
return
50
50
}
51
51
52
- activeRecord . leaveGuards . push (
53
- // @ts -ignore do we even want to allow that? Passing the context in a composition api hook doesn't make sense
54
- leaveGuard . bind ( instance . proxy )
55
- )
52
+ // @ts -ignore do we even want to allow that? Passing the context in a composition api hook doesn't make sense
53
+ const fn = leaveGuard . bind ( instance . proxy )
54
+ onUnmounted ( ( ) => {
55
+ const index = activeRecord . leaveGuards . indexOf ( fn )
56
+ if ( index > - 1 ) activeRecord . leaveGuards . splice ( index , 1 )
57
+ } )
58
+
59
+ activeRecord . leaveGuards . push ( fn )
56
60
}
57
61
58
62
/**
@@ -81,10 +85,14 @@ export function onBeforeRouteUpdate(updateGuard: NavigationGuard) {
81
85
return
82
86
}
83
87
84
- activeRecord . updateGuards . push (
85
- // @ts -ignore do we even want to allow that? Passing the context in a composition api hook doesn't make sense
86
- updateGuard . bind ( instance . proxy )
87
- )
88
+ // @ts -ignore do we even want to allow that? Passing the context in a composition api hook doesn't make sense
89
+ const fn = updateGuard . bind ( instance . proxy )
90
+ onUnmounted ( ( ) => {
91
+ const index = activeRecord . updateGuards . indexOf ( fn )
92
+ if ( index > - 1 ) activeRecord . updateGuards . splice ( index , 1 )
93
+ } )
94
+
95
+ activeRecord . updateGuards . push ( fn )
88
96
}
89
97
90
98
export function guardToPromiseFn (
0 commit comments