I am desperately to implement a navigation guard that will prevent users to access an item page if the item doesn't exist, based on the ID provided in route params.
It says in the Vue-Router guide that:
next(false): abort the current navigation. If the browser URL was changed(either manually by the user or via back button), it will be reset to that of the from route.
Yet in my component, using next(false) won't prevent the route change, or component rendering. It won't even navigate back as promised in the doc.
beforeRouteEnter(to, from, next) {
next(false)
ajaxcall$.subscribe(data => next(vm => vm.setData(data)))
I would have expected that obvious next(false)
to work and prevent the component and route from rendering but nope. The ajax call is made and the data is set.
return
statement to avoid executing the following expressions (i.e.return next(false)
). – Eliran Malkanext
is a callback. I don't think callbacks should be return values. It would break things. – igrekareturn
immediately after the callback invocation. – Eliran Malka