Skip to content
Discussion options

You must be logged in to vote

No. Vue Router does not provide an onBeforeRouteEnter() Composition API function.

beforeRouteEnter runs before navigation is confirmed and before the entering component instance exists. A composable called from that component's setup() would therefore be too late to act as that guard. This is why the Composition API exposes only onBeforeRouteUpdate() and onBeforeRouteLeave().

For enter-time checks, use a route-level guard:

{
  path: '/example',
  component: ExampleView,
  beforeEnter: (to, from) => {
    // return false to cancel, or a route location to redirect
  },
}

A global router.beforeEach() is another option. If you specifically need the post-entry component-instance callback, the …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants