The parameter carried by the route jump is an object or the parameter contains special characters

1. If the parameter is a string containing special characters

Such as: '我是一个字符&串', at this time, encoding and decoding processing is required

1. Encoding when passing parameters

/pages/page1?string=" + encodeURIComponent(String);

2. Decoding when getting parameters

//string:先获取路由参数string
let value = decodeURIComponent(string);

2. The parameter is an object, and it contains special characters

1. When passing parameters, first convert the object to a string before encoding

/pages/page1?object=" + encodeURIComponent(JSON.stringify(object));

2. Convert the receiving parameter into an object after decoding

//object: 获取路由参数object
let value = JSON.parse(decodeURIComponent(object));

reference:

  1. MDN official website encodeURIComponent: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
  2. decodeURIComponent: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent

Guess you like

Origin blog.csdn.net/honeymoon_/article/details/124130545