Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Cannot pass props in component from Vue router

Hi I'm trying to pass props from my vue router but it's not printing anything and when logged in mounted it's returning undefined, but its giving value when I'm trying console.log(this.$route.params.id); when I try for this.id returns undefined or rather in my User template its not outputting anything, same code is working in the online tutorial that I'm watching, please help me, is there any modification happened in a recent release

let User = {
  props: ['id'],
  template: `
            <div>Hello # {{id}}</div>
        `,
  mounted() {
    console.log(this.$route.params); // this is returning the value
    console.log(this.id); // this is giving undefined
  }
}

let App = {
  template: `
            <div class="wrapper">
                <router-view></router-view>    
            </div>
        `
}

let router = new VueRouter({
  routes: [{
    path: '/user/:id',
    component: User,
    props: true
  }, ],
})

let app = new Vue({
  el: '#app',
  router: router,
  components: {
    'app': App
  }
})

router.push('/user/1')
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>

<div id="app">
  <app></app>
</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using very old version of Vue Router. Just switch to current version - 3.5.2 - and your code will work as expected....

let User = {
  props: ['id'],
  template: `
            <div>Hello # {{id}}</div>
        `,
  mounted() {
    console.log(this.$route.params); // this is returning the value
    console.log(this.id); // this is giving undefined
  }
}

let App = {
  template: `
            <div class="wrapper">
                <router-view></router-view>    
            </div>
        `
}

let router = new VueRouter({
  routes: [{
    path: '/user/:id',
    component: User,
    props: true
  }, ],
})

let app = new Vue({
  el: '#app',
  router: router,
  components: {
    'app': App
  }
})

router.push('/user/1')
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@3.5.2/dist/vue-router.js"></script>

<div id="app">
  <app></app>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!