Skip to content
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

useRouter and useRoute failed when used inside plugin #554

Closed
BrandonlinU opened this issue Sep 24, 2022 · 1 comment · Fixed by #590
Closed

useRouter and useRoute failed when used inside plugin #554

BrandonlinU opened this issue Sep 24, 2022 · 1 comment · Fixed by #590

Comments

@BrandonlinU
Copy link

Environment

  • Operating System: Linux
  • Node Version: v16.17.0
  • Nuxt Version: 2.16.0-27720022.54e852f
  • Nitro Version: 0.5.4
  • Package Manager: pnpm@7.12.2
  • Builder: webpack
  • User Config: target, ssr, head, components, bridge, buildModules, modules, plugins, vuetify, hydra, publicRuntimeConfig, privateRuntimeConfig, build, router, serverHandlers, devServerHandlers
  • Runtime Modules: @instacarmx/nuxt-hydra@0.2.8
  • Build Modules: (), @nuxtjs/vuetify@1.12.3, @nuxt/bridge@3.0.0-27732833.edd9c5d

Reproduction

https://stackblitz.com/edit/github-zys9qe

Describe the bug

It seems that the Nuxt Plugin has no access to the Vue instance, so when I use a native composable to access to the router or the route, it throws an error saying that the Vue instance is not defined. It also cause error with other composables that use the native composables, such as navigateTo().

Additional context

I was upgrading the Nuxt Bridge from the version 3.0.0-27639120.e7a7f9b and using the new middleware router for an auth plugin when the console throw an error when I use the useRouter() and useRoute() from the #app namespace, so reading the changelog I discover the #533 pull request, so I update my imports according to use the native vue-router/composables namespace, causing the error in the console.

Logs

[nuxt] [request error] [vue-router]: Missing current instance. useRoute() must be called inside <script setup> or setup().
  at throwNoCurrentInstance (./.nuxt/dist/server/server.js:7304:11)  
  at useRoute (./.nuxt/dist/server/server.js:7318:5)  
  at eval (./.nuxt/dist/server/server.js:20653:88)  
  at callWithNuxt (./.nuxt/dist/server/server.js:2507:20)  
  at eval (./.nuxt/dist/server/server.js:2517:26)  
  at createApp (./.nuxt/dist/server/server.js:1047:85)  
  at async module.exports../.nuxt/server.js.__webpack_exports__.default (./.nuxt/dist/server/server.js:1602:7)  
  at async Object.renderToString (./node_modules/vue-bundle-renderer/dist/runtime.mjs:198:19)  
  at async eval (./.nuxt/dev/index.mjs:542:21)  
  at async eval (./.nuxt/dev/index.mjs:118:22)
@BrandonlinU
Copy link
Author

I can confirm that the solution worked, thanks you for the awesome work!

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

Successfully merging a pull request may close this issue.

1 participant