Skip to content

v2.0.0-rc.4

Pre-release
Pre-release
Compare
Choose a tag to compare
@yyx990803 yyx990803 released this 29 Aug 19:40
· 1294 commits to dev since this release

New

  • Now route components can also define the beforeRouteEnter hook, in addition to beforeRouteLeave. The difference here is that the before hook does not have access to this 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 the beforeRouteEnter 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