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

Get the store instance in the Vue router createRouter function #9594

Closed
loick opened this issue Jul 24, 2021 · 2 comments · Fixed by #9629
Closed

Get the store instance in the Vue router createRouter function #9594

loick opened this issue Jul 24, 2021 · 2 comments · Fixed by #9629

Comments

@loick
Copy link

loick commented Jul 24, 2021

Hi,

I'm currently using the router plugin (https://www.npmjs.com/package/@nuxtjs/router) in order to do the following behavior:

  • I'm importing several modules on the fly to compose my router regarding the user context. For example, a US user will have different routes available than a IT user.
  • I'm also adding conditions inside of the router to enable or not some routes depending on feature flags, which are in my Vuex store.

Here is actually the problem: I can't have any access to the Vuex store at this point. Since I already have it (for sure) instantiated before, I wonder if this is possible to retrieve the store object from the createRouter method in order for me to support my conditional imports.

https://github.com/nuxt/nuxt.js/blob/2ec62617ced873fef97c73a6d7aa1271911ccfd5/packages/vue-app/template/router.js#L104

I guess this is the place to look at, but it's weird to see the router initialized before the store here 🤔. Do you think it would have a big impact to create the store beforehand?
https://github.com/nuxt/nuxt.js/blob/eb6bd9febc63146622f56f9cb20511510400e6c5/packages/vue-app/template/index.js#L94-L105

Thanks!

Copy link
Member

Atinux commented Jul 28, 2021

Thank you for the detailed issue @loick

This is an interesting approach. I am not sure what it could break since we call the plugins and actions after both are initialized.

Do you mind opening a PR and keep discussing there to see how the tests react?

@loick
Copy link
Author

loick commented Jul 29, 2021

Sure no pb, I'm going to open it then :)

Thanks 🙏

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.

3 participants