@@ -11,7 +11,6 @@ import {
11
11
RouteResolver ,
12
12
Vue
13
13
} from './types/VueTypes'
14
- import { BasePluginError } from './lib/Exceptions/BasePluginError'
15
14
16
15
export const install : Install < Router | PluginOptions > = (
17
16
vue : Vue ,
@@ -21,9 +20,10 @@ export const install: Install<Router | PluginOptions> = (
21
20
throw new InvalidOptions ( )
22
21
}
23
22
23
+ const app : any = { }
24
24
let router : Router
25
25
let globalMiddlewares : Middleware [ ] = [ ]
26
- let context : RouteContext = { app : vue }
26
+ let context : RouteContext = { app }
27
27
28
28
if ( options && ( options as PluginOptions ) . router ) {
29
29
// if options object
@@ -58,22 +58,6 @@ export const install: Install<Router | PluginOptions> = (
58
58
router = options as Router
59
59
}
60
60
61
- // ==== helpers ============
62
- vue . $MiddlewarePlugin = true
63
- vue . $getMiddlewareContext = ( ) => {
64
- const { app, ..._context } = context
65
- return _context
66
- }
67
- vue . $setMiddlewareContext = ( _context : any ) : any => {
68
- const { app, to, from, redirect } = context
69
- context = { ..._context , app, to, from, redirect }
70
- return context
71
- }
72
- vue . $updateMiddlewareContext = ( key : string , value : any ) => {
73
- const { app, to, from, redirect } = context
74
- context = { [ key ] : value , app, to, from, redirect }
75
- }
76
-
77
61
/* istanbul ignore next */
78
62
const routeHook : RouteHook = (
79
63
to : Route ,
@@ -108,7 +92,23 @@ export const install: Install<Router | PluginOptions> = (
108
92
} else {
109
93
next ( )
110
94
}
95
+ }
96
+
97
+ router . beforeEach ( routeHook )
111
98
112
- router . beforeEach ( routeHook )
99
+ // ==== helpers ============
100
+ app . $MiddlewarePlugin = true
101
+ app . $getMiddlewareContext = ( ) => {
102
+ const { app, ..._context } = context
103
+ return _context
104
+ }
105
+ app . $setMiddlewareContext = ( _context : any ) : any => {
106
+ const { app, to, from, redirect } = context
107
+ context = { ..._context , app, to, from, redirect }
108
+ return context
109
+ }
110
+ app . $updateMiddlewareContext = ( key : string , value : any ) => {
111
+ const { app, to, from, redirect } = context
112
+ context = { [ key ] : value , app, to, from, redirect }
113
113
}
114
114
}
0 commit comments