Recently to learn about, vue-router routing hook function, I believe many, a simple summary here as long as the front end of the small school partners contact you, we want to help small partners.
Routing hook function following three types:
first: global hook function .
router.beforeEach ((to, from, Next) => {
the console.log ( 'beforeEach')
// Next () // if to jump, it must write the Next ()
// Next (to false) // canceled navigation
next () // jump normal, not write, not Skip
})
router.afterEach ((to, from) => {// example: by changing the jump document.title
IF (to. meta.title) {
the window.document.title = to.meta.title at each routing // title
} {the else
the window.document.title = 'default title'
}
})
the second: routing for a single hooking function
beforeEnter (to, from, Next) {
the console.log ( 'beforeEnter')
Next () // jump normal, not write, not Skip
}
Third: the component level hook function
beforeRouteEnter (to, from, next) {// this function to perform routing hook than life cycle beforeCreate function, so this instance has not been created out
console.log ( "beforeRouteEnter")
console.log ( this) // then this is undefinde, because this time this instance has not been created out of the
next ((vm) => { // vm, this can vm this parameter to get this instance, then you can make changes to the
vm.text = 'changed'
})
},
beforeRouteUpdate (to, from, the Next) {// can be resolved when the two navigation, page rendering only one problem, that is, whether to update the navigation, the need to update
console.log ( 'beforeRouteUpdate ')
Next ();
},
beforeRouteLeave (to, from, Next) {// when leaving the assembly is allowed to leave the
Next ()
}
vue-router routing hook function basic usage summary
Guess you like
Origin www.cnblogs.com/web-develper/p/11365432.html
Recommended
Ranking