-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add onBeforeRouteEnter
API to the list of composition API
#1517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
hello,may I get a case to put beforeRouteEnter into <script setup>. |
@posva Can you help us understand a little more on this? I'm confused because beforeRouteEnter exists in options API here: https://router.vuejs.org/guide/advanced/navigation-guards.html#using-the-composition-api Not sure why it then couldn't be made to be used inside of setup() ? Could it be done in a PR, or is there a reason why it hasn't been done? |
It’s a technical limitation: setup runs when the component is created which happens after the navigation. Therefore you cannot add a navigation guard while the component is created |
@posva Hi! Can we do onBeforeRouteEnter hook using compiler macros? We can add this hook using defineOptions({
beforeRouteEnter: preloadGuard(() => loadInitial())
}); Also it would be nice to add route meta from component like nuxt doing |
The prefered direction are data loaders: https://uvr.esm.is/data-loaders/. You also have a |
Upgrade the playground package to use the `<script setup>` syntax and TypeScript. This change makes the playground more consistent with recent Vue.js practices and improves type safety. Keep the purpose of each example identical to the original examples as much as possible. Therefore, components using `beforeRouteEnter()`, [which does not have a `<script setup>` equivalent](vuejs#1517), are not converted to `<script setup>` syntax but are only converted to use TypeScript for improved type safety (Home.vue and ComponentWithData.vue). Converting these to use the [recommended data loaders or `defineMacro()`](vuejs#1517 (comment)) could be an option in the future. Update `RouteNamedMap` in main.ts to improve type safety and better demonstrate the newer typed routes feature (introduced in [email protected]) in LongView.vue, Nested.vue, and RepeatedParams.vue. Fix type issue in AppLink.vue where `RouterLinkProps` replaces `RouterLink.props`. Remove the `name` option from the `defineComponent` calls that used it, because this option is [only useful when the component recursively calls itself](https://v2.vuejs.org/v2/api/#name), but there are not components in this playground project that do so.
What problem does this feature solve?
Current the documentation about composition API https://router.vuejs.org/guide/advanced/navigation-guards.html#using-the-composition-api doesn't mention about
onBeforeRouteEnter
. I see inOptions API
, there isbeforeRouteEnter
hence there should be one for composition API too.What does the proposed API look like?
The text was updated successfully, but these errors were encountered: