UNPKG

dd-uni-simple-router

Version:

> 一个更为简洁的[Vue-router](https://router.vuejs.org/zh/),专为 [uni-app](https://uniapp.dcloud.io/) 量身打造

37 lines (33 loc) 1.59 kB
import { navtoRule, navErrorRule, Router, proxyHookName, guardHookRule, totalNextRoute, hookToggle} from '../options/base'; import { LifeCycleConfig, InstantiateConfig} from '../options/config'; import {onTriggerEachHook} from '../public/hooks' export function registerHook(list:Array<Function>, fn:Function):void { list[0] = fn; } export function registerRouterHooks<T extends LifeCycleConfig>(cycleHooks:T, options:InstantiateConfig):T { registerHook(cycleHooks.routerBeforeHooks, function(to:totalNextRoute, from: totalNextRoute, next:(rule?: navtoRule|false)=>void):void { (options.routerBeforeEach as Function)(to, from, next); }) registerHook(cycleHooks.routerAfterHooks, function(to:totalNextRoute, from: totalNextRoute):void { (options.routerAfterEach as Function)(to, from); }) registerHook(cycleHooks.routerErrorHooks, function(error:navErrorRule, router:Router):void { (options.routerErrorEach as Function)(error, router); }) return cycleHooks; } export function registerEachHooks(router:Router, hookType:proxyHookName, userGuard:guardHookRule) { registerHook(router.lifeCycle[hookType], function( to:totalNextRoute, from: totalNextRoute, next:(rule?: navtoRule|false)=>void, router:Router, auto:boolean, ):void { if (auto) { // h5端 vue-router自动触发 非自己调用触发 onTriggerEachHook(to, from, router, hookToggle[hookType], next) } else { userGuard(to, from, next) } }) }