@@ -34,6 +34,12 @@ export function onBeforeRouteLeave (guard) {
34
34
return useFilteredGuard ( guard , isLeaveNavigation )
35
35
}
36
36
37
+ function registerGuard ( router , guard , fn , depth ) {
38
+ return router . beforeEach ( ( to , from , next ) => {
39
+ return fn ( to , from , depth ) ? guard ( to , from , next ) : next ( )
40
+ } )
41
+ }
42
+
37
43
const noop = ( ) => { }
38
44
function useFilteredGuard ( guard , fn ) {
39
45
const instance = getCurrentInstance ( )
@@ -56,17 +62,11 @@ function useFilteredGuard (guard, fn) {
56
62
: null
57
63
58
64
if ( depth != null ) {
59
- const registerGuard = ( ) => {
60
- return router . beforeEach ( ( to , from , next ) => {
61
- return fn ( to , from , depth ) ? guard ( to , from , next ) : next ( )
62
- } )
63
- }
64
-
65
- let removeGuard = registerGuard ( )
65
+ let removeGuard = registerGuard ( router , guard , fn , depth )
66
66
onUnmounted ( removeGuard )
67
67
68
68
onActivated ( ( ) => {
69
- removeGuard = removeGuard || registerGuard ( )
69
+ removeGuard = removeGuard || registerGuard ( router , guard , fn , depth )
70
70
} )
71
71
onDeactivated ( ( ) => {
72
72
removeGuard ( )
0 commit comments