项目需要,之前的显性传值改为隐性传值:
//显性传值
router.push( pathname:`/bondApproval?id=${id}&type=haveTodo&title=标题`);
//隐性传值
const path = {
pathname: '/approval',
state: {
type: 'haveTodo',
id,
title:'标题'
}
}
router.push(path);
获取方式:
//显性传值获取方式
const getParamValue = (target) => {
const search = window.location.search.substring(1);
const params = search.split('&');
for (let i = 0; i < params.length; i++) {
const param = params[i].split('=');
if (param[0] === target) {
return param[1];
}
}
return false;
}
const id = getParamValue ('id')
//隐性传值获取方式
this.props.location.state