Skip to content

docs: using beforeRouteEnter with defineOptions #2131

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

Conversation

skirtles-code
Copy link
Contributor

This addition to the docs attempts to address two common problems:

  1. beforeRouteEnter doesn't have a Composition API function. This is often perceived as an oversight or mistake, as it isn't immediately obvious that such a function isn't possible.
  2. It seems that many people conclude that they can't use beforeRouteEnter if they're using the Composition API.

Copy link

netlify bot commented Feb 6, 2024

Deploy Preview for vue-router ready!

Name Link
🔨 Latest commit 9a190b0
🔍 Latest deploy log https://app.netlify.com/sites/vue-router/deploys/65c1d413d999a000084237dc
😎 Deploy Preview https://deploy-preview-2131--vue-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

```vue
<script setup>
// Using defineOptions requires Vue 3.3+
defineOptions({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about two things:

  • The example uses defineOptions() so it makes it look like you can use setup stuff inside beforeRouteEnter()
  • I would not recommend using this navigation guard at the moment as I plan data loaders to be a much better approach to the same problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The potential confusion around variable scope is a really good point and not something I'd considered. While this is still something I'd be happy to do myself, it does muddy the waters from a docs perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants