Skip to content

router hook that executes after route leave but before route enter on reused route components #1885

@autumnwoodberry

Description

@autumnwoodberry

What problem does this feature solve?

This will allow asynchronous code to prevent entering a new route, while allowing the current route component to exit.

Imagine you have a route component that requires some data to be fetched from the server before entering. If the route params change and the data needs to be refreshed, there is currently not a router hook that will allow the current component to transition out before fetching the new data.

A forum post is here: https://forum.vuejs.org/t/beforerouteenter-beforerouteupdate/21661

A codepen example is here: https://codepen.io/autumnwoodberry/pen/NwaxLZ

What does the proposed API look like?

afterUpdateBeforeEnter (to, from, next) {
  return http.fetch(to.params.slug).then(next)
}

Basically, this would function exactly like beforeRouteUpdate, but will allow the current component to leave before executing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions