Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass custom property via vue router

I have a route instance:

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: MainContainer,
      redirect: '/news/list',
      children: [
        {
          path: 'advertisement/create',
          name: 'Create Advertisement',
          title: 'This is title of the page'
          component: CreateAdvertisement
        }
      ]
    }
  ]
})

In my component, i tried to console this.$route but I got only name, path, component and there is no title property there. So my question is: Is this valid to pass a custom property via Vue router? If there is, where the problem with my attemp?

like image 960
vicnoob Avatar asked Nov 04 '25 14:11

vicnoob


1 Answers

You can add to the meta:

 const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: MainContainer,
      redirect: '/news/list',
      children: [
        {
          path: 'advertisement/create',
          name: 'Create Advertisement',
          title: 'This is title of the page'
          component: CreateAdvertisement,
          meta:{
           // here
           key: value
          }
        }
      ]
    }
  ]
})

https://router.vuejs.org/guide/advanced/meta.html

like image 189
JasonZeng Avatar answered Nov 07 '25 09:11

JasonZeng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!