Created
December 7, 2020 13:10
-
-
Save NovoManu/1cedfdeee0442e1bed83ddc53d3671d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import VueRouter from 'vue-router' | |
import routes from './routes' | |
Vue.use(VueRouter) | |
export default Promise.all(routes).then(routes => { | |
const router = new VueRouter({ | |
mode: 'history', | |
routes | |
}) | |
router.beforeEach((to, from, next) => { | |
if (!to.meta.middlewares) { | |
return next() | |
} | |
const middlewares = to.meta.middlewares | |
Object.keys(middlewares).forEach(middleware => { | |
middlewares[middleware]({ to, from, next }) | |
}) | |
return next() | |
}) | |
return router | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment