Why doesn't Vue3 router not pass props with params?

Viewed 1953

I want to pass a value to a view as prop in Vue3. This approach work well in Vue2 project but doesn't in Vue3

Router:

{      
  path: "/view2",
  name: "view2",
  component: View2,
  props: true
}

View 1 (from)

navigateTo(){
    this.$router.push({
      name: view2,
      params: {id: 'abc123'}
    })
}

View 2 (to)

props:{
  id:{
    type: String,
    required: false
  }
}

Each time the navigateTo() is called, the 'id' is undefined in View2

What am I missing cause this works well in vue2 project.

Best

1 Answers

You did not declare id in your path.

{      
  path: "/view2/:id", // <----
  name: "view2",
  component: View2,
  props: true
}
Related