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

feat: allow Vue component to receive a VueRouter factory #2791

Closed
wants to merge 2 commits into from

Conversation

Silentscripter
Copy link

In some situations (for ex. micro-frontend architectures where vue apps are wrapped in web-components) it would be good to have different VueRouter instances when a wrapped vue app is destroyed and recreated (since normally the VueRouter is created before and referenced in Vue component options).

@posva
Copy link
Member

posva commented May 31, 2019

Hi, I don't get why you can't reuse the same router instance

@Silentscripter
Copy link
Author

hi posva, in micro-frontend architecture we usually wrap vue apps in web-component to reuse as independent widget in another SPA. As for vue component option design if you happen to destroy and recreate one of these widget (for ex routing from a page to another and back) you find the widget to be in the last route since even if the vue app is destroyed, the reference of the router that will be taken by the new vue app is the same.
Another case is when you use the same widget on the same page more than once: they share the same router unde the hood and whenin you push a route in a widget all will follow.
With this addition you can assure that vue router is created on the vue root instance during the beforeCreate lifecycle and is assured to be linked to that vue app only.

@Silentscripter
Copy link
Author

Forgot to mention that Vuex, for example, has taken the same approach in its mixin beforeCreate hook.

@Turaylon
Copy link

Turaylon commented Jun 3, 2019

I need this on my project too, hope it will merged.
As i can see is a feat that does not break anything on current usage, but is a plus for usage in multiple instances of Vue as web components.

@AndreaPaciolla
Copy link

Hi there,
any update on this topic?

Could be useful for me too.

@exoego
Copy link

exoego commented Sep 9, 2019

@posva
Vuex already has same capability via options.store: it can be function as factory.
https://github.com/vuejs/vuex/blob/caa663d69608fc36d1a88746df28961437d38786/src/mixin.js#L26

@Silentscripter
Could you resolve conflict?

@exoego
Copy link

exoego commented Oct 23, 2019

@Silentscripter
Just a kind reminder regarding conflict.

@Silentscripter
Copy link
Author

Sorry for the delay, I've been busy these days. Will fix in this week for sure!

@Silentscripter
Copy link
Author

conflict resolved

@posva
Copy link
Member

posva commented Dec 8, 2019

The problem with this is that this should not be enough as router instances do not have a way to be destroyed yet (releasing listeners and others). So there is a few more things to check first

@posva posva added the micro frontends Features to handle micro frontends label Dec 8, 2019
@Silentscripter
Copy link
Author

I will try to have a look for a solution, thanks for your comment

@posva
Copy link
Member

posva commented Jun 24, 2020

Hello I'm coming back to this since a different PR that should help micro frontends was merged and released recently #3172

The corresponding API added to Vuex was to delay the store instantiation (vuejs/vuex#798)

I'm still confused by why you need a function here. Don't you instantiate the root component again?

function createVueApp() {
  // cleanup existing #app element
  const router = new Router()
  new Vue({ router, el: '#app' })
}

@posva
Copy link
Member

posva commented Aug 3, 2020

Closing due to inactivity. Please open a new issue with a reference to this one if you can follow up with more information.

@posva posva closed this Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request micro frontends Features to handle micro frontends
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants