import { NavigationGuard , Route , RouteRecord , VueRouter } from 'vue-router/types/router' ; import { Access } from '../Access' ; import RouterMiddleware from './RouterMiddleware' ; import { assert } from '../util' ; import flatten from 'lodash/flatten' ; import map from 'lodash/map' ; import get from 'lodash/get' ; const beforeEach = function ( this , to , from , next ) { let app = this . app . $options ; let access = app . access as Access ; if ( ! ( access && access . accessRouterMiddleware ) ) { next ( ) ; return assert ( true , 'not be install correct or not open route middleware function' ) ; } let routerMiddleWare = access . accessRouterMiddleware as RouterMiddleware ; let matched = to . matched ; let middleware = flatten ( map ( matched , ( item ) => get ( item , 'meta.middleware' , [ ] ) ) ) ; routerMiddleWare . runMiddleware ( { middleware : middleware , next : next , } , this , to , from ) ; } ; export default beforeEach ;