javascript - How to set afterEach handler in vue-router -
i have following script:
import vue 'vue' import router 'vue-router' vue.use(router) export default new router({ scrollbehavior (to, from, savedposition) { // purposely left blank }, routes: [ { path: "/", component: samplecomponent } ] } i add aftereach handler router can close open menus when router link taken.
i tried add constructor not constructor argument.
i tried:
router.aftereach((to, from) => { // ... }) but error:
aftereach not function
how appropriately add aftereach callback setup?
you need set aftereach handler on router instance (the object returned via new router()).
you can set reference instance, , add aftereach handler before it's exported:
const router = new router({ scrollbehavior (to, from, savedposition) { // purposely left blank }, routes: [ { path: "/", component: samplecomponent } ] }); router.aftereach((to, from) => { // ... }); export default router
Comments
Post a Comment