UNPKG

551 BJavaScriptView Raw
1/*
2 * 初始化路由配置
3 */
4
5import VueRouter from 'vue-router'
6
7export function configRouter({ base, routes, historyMode, beforeEach, afterEach, onReady }) {
8 const promise = new Promise(function(resolve) {
9 const router = new VueRouter({
10 base: base || '',
11 routes,
12 mode: historyMode || 'hash'
13 })
14 if (beforeEach) {
15 router.beforeEach(beforeEach)
16 }
17 if (afterEach) {
18 router.afterEach(afterEach)
19 }
20 if (onReady) {
21 router.onReady(onReady)
22 }
23 resolve(router)
24 })
25 return promise
26}