Repository navigation
Does it have "onBeforeRouteEnter" in vue composition api? #2583
|
https://router.vuejs.org/api/functions/onBeforeRouteLeave.html I can't find "onBeforeRouteEnter" this function in doc API Functions list. |
Replies: 1 comment
|
No. Vue Router does not provide an
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 This lifecycle difference is documented under Navigation Guards. |
No. Vue Router does not provide an
onBeforeRouteEnter()Composition API function.beforeRouteEnterruns before navigation is confirmed and before the entering component instance exists. A composable called from that component'ssetup()would therefore be too late to act as that guard. This is why the Composition API exposes onlyonBeforeRouteUpdate()andonBeforeRouteLeave().For enter-time checks, use a route-level guard:
A global
router.beforeEach()is another option. If you specifically need the post-entry component-instance callback, the …