Interview questions related to routing transfer parameters

1) Can the route transfer parameters (object writing) path be used in conjunction with the params parameter?

No: You cannot write it like this, the program will crash.

The combination of path and params configuration cannot be used, only the combination of name and params configuration can be used.

Query configuration can be used in combination with path or name

2) How to specify whether the params parameter can be passed or not?

For example: when configuring the route, the params parameter is occupied, but it is not passed when the route jumps.

If the route requires the params parameter to be passed, but it is not passed, there will be problems with the URL​​​​​​​

Can I add one after the placeholder when configuring the route? number, indicating that the params parameter can be passed or not.

{
    path:"/Search/:keyword?",
    component:Search,
    meta: { show: true },
    name:"search"
},

3) The params parameter can be passed or not, but if it is an empty string, how to solve it?

If you specify name and params configuration, but the data in params is " ", it cannot jump, and there will be a problem with the path.

Solution 1: Do not specify params

Solution 2: Specify the params parameter value as undefined

this.$route.push({
  name:"search",
  params:{
    keyword:''||undefined
  }
)

4) Can routing components pass props data?

Yes: Query or params parameters can be mapped/converted into props and passed to the routing group

Guess you like

Origin blog.csdn.net/weixin_44359444/article/details/126920646