0
votes

I'm wondering if I can use the parameter from path in vue-router's meta data field. For instance, here I am using the parameter entity_id in the path.. but, I want to also use that parameter as a property/parameter in the meta property so that I can use it more easily:

{
    path     : ':entity_id',
    name     : 'DashboardEntity',
    component: DashboardEntity,
    meta     : {
        label: 'Example',
        iwantthistobetheid: ':entity_id'
    },
},

The reason is that I have a breadcrumb file that lists out the routes/children/etc. and I want to display the ID in the breadcrumb.

I can do that in the above example by using this.$route.params.entity_id in my breadcrumb view.. but then I have to name every parameter in my routes something generic like id to have it display every time.

Any idea of how this might be possible or a solution that doesn't require me to either rename all my router parameters or have a huge if/else to check each routers params to display in my breadcrumb view?

1

1 Answers

0
votes

You should be able to do this:

this.$route.params[this.$route.meta.iwantthistobetheid]

that would be the equivalent of

this.$route.params.entity_id

or if iwantthistobetheid = 'object_id'

this.$route.params.object_id