-
-
Notifications
You must be signed in to change notification settings - Fork 5k
$route.matched[i].instances loses references to instances when router view components are reused #1338
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
This is also happening with webpack hot module replacement. After the first change |
And this is the exact commit where it stops working: 4e3b377 |
@ernestoalejo I should add that I had issues with the scenario describe above with versions prior v2.4.0 as well, e.g. that no instances were available yet in |
...and related this issue, I was wondering when working with nested components why there isn't a standardised way for a matched component at any level of the hierarchy to know the part of the route that matched it, and the
This is why i wrote the code posted above, and that's where I am hitting this bug because I cannot rely on the |
@lehni regarding your last comment, it is indeed possible (although undocumented) - you can access the depth of a router-view component with this.$route.matched[this.$vnode.data.routerViewDepth].meta |
@yyx990803 thanks! Would you consider exposing this? e.g.: computed: {
$routeRecord() {
return this.$route.matched[this.$vnode.data.routerViewDepth]
},
$meta() {
return this.$routeRecord.meta
}
} |
This seems to be an issue again since vue v2.5.15 (which adds just a single commit: 8200a35). |
@apexo thanks, will look into this. |
The reproduction uses v3.0.1 and it is is still producing the issue .. |
This is already fixed (again) in Vue core, will be out in next patch release. |
for reference: vuejs/vue@de42278 |
Requires vuejs/vue-router#1338 to be fixed.
Dirty but it seems to do the trick!
Version
2.4.0
Reproduction link
http://jsfiddle.net/lehni/Lb0hz1b0/
Steps to reproduce
Click on any of the two router links in the linked example. In the first view, you will see that a reference to the default view instance is defined.
What is expected?
I expect the instances reference to always point to the mapped router view component instances.
What is actually happening?
After navigating to the second link, the reference is gone, although the view component is reused.
I noticed this because I am using the meta field to attach data to routes that are auto-generated from an admin editor schema description described in JavaScript object literals, out of which the full admin is built automatically. I needed a way to retrieve these meta fields in the associated instances of my router view components, and the only way I found to work was:
But the route record object loosing the references to the instances breaks this.
It would be nice to have a $meta and $routeRecord property available that link the router view component instances to the associated route record and attached meta data.
Another scenario where I needed this is the
isLastRoute
property that you can see above, to know if my template needs to provide another router-view or wether it can render its own content, facilitating automatic nesting based on the schema.The text was updated successfully, but these errors were encountered: