Solve the problem that uni.switchTab in uniapp cannot pass parameters
Problem Description
在uniapp中使用uni.switchTab无法传参
uni.switchTab({
url:`/pages/report/report?Id=${
query}`
})
Cause Analysis
uniapp officially defines that uni.switchTab cannot pass parameters
parameter | type | required | illustrate |
---|---|---|---|
url | String | yes | The path of the tabBar page that needs to be redirected (the page defined in the tabBar field of pages.json), the path cannot be followed by parameters |
success | Function | no | Callback function for successful interface call |
fail | Function | no | Callback function for interface call failure |
complete | Function | no | The callback function of the end of the interface call (the call will be executed successfully or failed) |
solution
Use uni.relaunch to jump and carry parameters
parameter | type | required | illustrate |
---|---|---|---|
url | String | yes | The path of the in-app page that needs to be redirected, with parameters after the path. Parameters and paths are separated by ?, parameter keys and parameter values are connected by =, and different parameters are separated by &; such as 'path?key=value&key2=value2', if the redirected page path is a tabBar page, parameters cannot be included |
success | Function | no | Callback function for successful interface call |
fail | Function | no | Callback function for interface call failure |
complete | Function | no | The callback function of the end of the interface call (the call will be executed successfully or failed) |
uni.redirectTo({
url:`/pages/report/report?Id=${
query}`
})