@@ -11,7 +11,6 @@ import {
1111 RouteResolver ,
1212 Vue
1313} from './types/VueTypes'
14- import { BasePluginError } from './lib/Exceptions/BasePluginError'
1514
1615export const install : Install < Router | PluginOptions > = (
1716 vue : Vue ,
@@ -21,9 +20,10 @@ export const install: Install<Router | PluginOptions> = (
2120 throw new InvalidOptions ( )
2221 }
2322
23+ const app : any = { }
2424 let router : Router
2525 let globalMiddlewares : Middleware [ ] = [ ]
26- let context : RouteContext = { app : vue }
26+ let context : RouteContext = { app }
2727
2828 if ( options && ( options as PluginOptions ) . router ) {
2929 // if options object
@@ -58,22 +58,6 @@ export const install: Install<Router | PluginOptions> = (
5858 router = options as Router
5959 }
6060
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-
7761 /* istanbul ignore next */
7862 const routeHook : RouteHook = (
7963 to : Route ,
@@ -108,7 +92,23 @@ export const install: Install<Router | PluginOptions> = (
10892 } else {
10993 next ( )
11094 }
95+ }
96+
97+ router . beforeEach ( routeHook )
11198
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 }
113113 }
114114}
0 commit comments