First of all, my route definition
{
path: '/b',
name: 'B',
component: resolve => require(['.. /pages/B.vue'], resolve)
}Copy the code
I jump from component A to component B and pass some parameters through the routing information object
this.$router.push({
path: '/b',
params: {
paramA: 'a'
},
query:{
paramB: 'b'}})Copy the code
Get parameters in component B
this.$route.query.paramB //b
this.$route.params.paramA //undefinedCopy the code
The parameter paramB passed through the routed params object is always undefined.
The reason is that a route must be called by the name of the route used by params objects, rather than by path, which is not required by query objects. So let’s change the code:
this.$router.push({
name: 'B',
params: {
paramA: 'a'
},
query:{
paramB: 'b'}})Copy the code
Change the path parameter to the route name, and everything will be fine.
this.$route.query.paramB //b
this.$route.params.paramA //aCopy the code