naive-ui/demo/routes/router.js

28 lines
566 B
JavaScript
Raw Normal View History

import { createRouter, createWebHistory } from 'vue-router'
2020-03-20 17:32:05 +08:00
2020-09-27 22:27:25 +08:00
export const loadingBarApiRef = {}
export default function createDemoRouter (app, routes) {
const router = createRouter({
history: createWebHistory(),
2020-03-20 17:32:05 +08:00
routes
})
2020-09-27 22:27:25 +08:00
router.beforeEach(function (to, from, next) {
if (loadingBarApiRef.value) {
loadingBarApiRef.value.start()
}
next()
})
router.afterEach(function (to, from) {
if (to.path !== from.path) {
if (loadingBarApiRef.value) {
loadingBarApiRef.value.finish()
}
}
})
2020-03-20 17:32:05 +08:00
return router
}