v2.0.0-rc.4
Pre-releaseNew
-
Now route components can also define the
beforeRouteEnter
hook, in addition tobeforeRouteLeave
. The difference here is that the before hook does not have access tothis
because it is called before the route is even confirmed (thus no component instance has been rendered yet).In some use cases, the user may want to use the hook to pre-fetch data before switching to the new route. However without a reference to the incoming instance there's no easy way to pass the data. To solve that, the
next
function for thebeforeRouteEnter
hook accepts a callback, which will be called with the vm instance once the route has been rendered:export default { data () { return { msg: null } }, beforeRouteEnter (route, redirect, next) { fetchData(route.params.id, msg => { next(vm => { vm.msg = msg }) }) } }
Note whether to use this pattern is ultimately a UX decision: it depends on whether you want to wait until data is resolved before switching to the new route, or do you want to switch instantly, and let the incoming component handle the fetching and loading state. Both are valid choices, so we are providing the API to achieve both.
-
Support returning Promises for async components
Fixed
- #622 fix named routes active class matching