1๐
โ
Try writting it in this form
beforeRouteEnter(to, from, next) {
next(async (vm) => {
await axios...
if(...) {
next()
} else {
next(false) // in case the navigation needs to be blocked
}
})
}
That way, it should wait for the result before resolving the navigation.
If you only need this check on pages
, you can also use asyncData
to get data before even navigating to the next page (it will block until resolved). Beware tho, because an F5 on the targetted page will not trigger this hook.
Source:stackexchange.com