Open
Description
What problem does this feature solve?
This will allow users to hook on:
- redirections to the current route (could be a different hook like
onRedirect
, also triggered byredirect
option) next(false)
calls- navigation delayed and replaced by other navigations:
- eg: users click when async component not finished loading
I'm a bit sceptical about use cases on why to hook on redirects, so I'll love to read if you have usecases
What does the proposed API look like?
router.onCancel((to, from, currentLocation) => {
// from -> original route where the navigation was triggered
// to -> where was it supposed to go
// currentLocation -> location where we ended up (same as this.$route in components and router.currentRouter
})
can be triggered by
router.beforeEach((to, from, next) => {
next(false) // cancel navigation explicitely
})
router.beforeEach((to, from, next) => {
to.fullPath // /foo
from.fullPath // /home
// redirect to /home if we're on /foo
// this will do nothing if we are already on /home
if (to.fullPath === '/foo') next('/home')
else next()
})