naive-ui/demo/routes/router.js

23 lines
504 B
JavaScript
Raw Normal View History

2020-03-20 17:32:05 +08:00
import VueRouter from 'vue-router'
export default function createRouter (Vue, routes) {
const router = new VueRouter({
mode: 'history',
routes
})
router.beforeEach(function (to, from, next) {
Vue.prototype.$NLoadingBar.theme = to.params.theme
if (to.path !== from.path) {
Vue.prototype.$NLoadingBar.start()
}
next()
})
router.afterEach(function (to, from) {
if (to.path !== from.path) {
Vue.prototype.$NLoadingBar.finish()
}
})
return router
}