-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expose RouterLink and RouterView components #1976
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
Why not use const RouterView = Vue.component('router-view');
const RouterLink = Vue.component('router-link'); |
@JounQin I didn't know you could use Vue component like that. The problem is you need Vue Router installed on the Vue instance, which adds const localVue = createLocalVue()
localVue.use(VueRouter)
const RouterLink = localVue.component('router-link');
const wrapper = shallow(Comp, { localVue })
wrapper.find(RouterLink).props().to Which I suppose isn't too bad 🤔 |
@eddyerburgh I "not too bad" good enough to close this? :-P |
I think we still need the change for two reasons:
|
Looks good to me and it's very easy to add. What do you think? @yyx990803 |
I think that's good to have. Open to PR. |
This would be a breaking change for the common js or browser build. We can export them in vue-test-utils instead |
It would be so much better if we could avoid Router injecting global That way we will have self-contained components. Right now they are relying on obscure globally injected component, which you need to re-added during tests by using whole router instance, instead of declaring it imports at first place — in the component itself. |
I suppose this is rejected and we should follow #1976 (comment)? |
@ArmorDarks made a good case for this. I also just ran into this issue. Our component library, using its own set of node_modules, uses a different Vue instance which doesn't have the component. Being able to explicitly import it would solve this issue. This seems like a simple non-breaking change. |
Here's a tentative PR: #2853 As mentioned by @eddyerburgh, we can't add additional exports to the umd/browser builds because they only support a single default export. We can however add them to the ES module builds without breaking backwards compatibility. I assume anyone interested in this feature is using ES modules anyway. I concede that it is a bit hacky though. |
Finally, I am also convinced that this is not needed in vue-router. Here's the summary:
const RouterView = Vue.component('router-view');
const RouterLink = Vue.component('router-link');
Case closed, as far as I can tell. |
What problem does this feature solve?
Currently it's not possible to find RouterLink and RouterView when using vue-test-utils. You can find the rendered content, but if you want to check that a RouterLink receives the correct to property, you need to check the tag renders an href:
We're considering adding a RouterLink stub to vue-test-utils, so you can do this:
But adding a stub basically means reimplimenting the RouterLink, since we don't actually need to stub it, we just need to have access to the component as a selector.
Instead, would we be able to expose RouterLink and RouterView from Vue Router?
What does the proposed API look like?
We could import the components with the same name they are registered with:
The text was updated successfully, but these errors were encountered: