Skip to content

Expose meta in Route objects #602

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

Merged
merged 3 commits into from
Aug 10, 2016
Merged

Expose meta in Route objects #602

merged 3 commits into from
Aug 10, 2016

Conversation

fnlctrl
Copy link
Member

@fnlctrl fnlctrl commented Aug 10, 2016

Expose route.meta to allow reading RouteConfig.meta in transition hooks.

Reasons:
In 1.0, we used to pass Custom Fields( like auth in route configs, as the document suggested), but in 2.0 these custom fields aren't exposed in route object.
I've noticed that in RouteConfig, there is an optional field meta, which i guess serves the functionality of the previous Custom Fields, judging from the fact that 1). It's type is any 2).there are no usage references of it in the source code.
So I guess meta should be exposed in route objects, otherwise there is no need to define it in the first place.

Expose route.meta to allow reading RouteConfig.meta in transition hooks.

Reasons: 
In 1.0, we used to pass Custom Fields( like `auth` in route configs, as the [document](http://router.vuejs.org/en/route.html#custom-fields) suggested), but in 2.0 these custom fields aren't exposed in `route` object.
I've noticed that in `RouteConfig`, there is an optional field `meta`, which i guess serves the functionality of the previous Custom Fields, judging from the fact that 1). It's type is any 2).there are no references of it in the source code. 
So I guess `meta` should be exposed in route objects, otherwise there is no need to define it in the first place.
@LinusBorg
Copy link
Member

LinusBorg commented Aug 10, 2016

You already can access meta:

In the next branches examples, there's already an example using the meta property:

set meta:
https://github.com/vuejs/vue-router/blob/next/examples/navigation-guards/app.js#L53
Read meta:
https://github.com/vuejs/vue-router/blob/next/examples/navigation-guards/app.js#L61

@fnlctrl
Copy link
Member Author

fnlctrl commented Aug 10, 2016

@LinusBorg meta's not accessible in $route, unfortunately..

@LinusBorg
Copy link
Member

LinusBorg commented Aug 10, 2016

it's accessible through the routeRecord objects in the $route.matched array, if I'm not mistaken

https://github.com/fnlctrl/vue-router/blob/4c5c0469f2d8a4cc41f39f8409b188e59d7137f1/src/create-matcher.js#L135

This has the added benefit of providing access to the parent routeRecord's meta, as well.

@yyx990803 yyx990803 merged commit 441f554 into vuejs:next Aug 10, 2016
@fnlctrl fnlctrl deleted the patch-1 branch August 11, 2016 05:45
@fnlctrl
Copy link
Member Author

fnlctrl commented Aug 11, 2016

@LinusBorg Thanks! I wasn't looking inside matched because it was something completely different in 1.0, and I couldn't find relevant information in the release notes. I would have argued that it's less convenient/straightforward than in 1.0 and then just move on to use route.matched instead, but since the PR is merged there's no need and I'm very grateful for this change :).

@yyx990803
Copy link
Member

@fnlctrl note the meta exposed is only that of the deepest matched sub route. In a lot of cases you will still want to iterate through all matched routes.

@fnlctrl
Copy link
Member Author

fnlctrl commented Aug 11, 2016

@yyx990803 I see...Thanks for the note!

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

Successfully merging this pull request may close these issues.

3 participants