一、重要代码
const urlParams = new URL(window.location.href).searchParams;
history.push(urlParams.get('redirect') || `/跳转的网页path?${paramsText}`);
//参数格式:
paramsText = project_name=${record["project_name"]} && project_name=${record["project_name"]}
二、columns里的操作
{title:'操作',valueType: 'option', key: 'option', align:"center",width:"10%",
render: (text, record) => [
<a style={{ marginLeft: '2%' }} onClick={()=>{
const urlParams = new URL(window.location.href).searchParams;
console.log("urlParams",urlParams)
let paramsList = Object.entries(record)
console.log("paramsList",paramsList)
const paramsText = paramsList.map(([k,v])=>{
if(v){
return `${k}=${v}`
}
}).join("&&")
console.log("paramsText",paramsText)
history.push(urlParams.get('redirect') || `/yewu/applyInfo?${paramsText}`);
}}>跳转按钮</a>
]
}
三、接收参数
queryParams就是接受的参数
formRef将他传给Form组件里
import { parse } from 'query-string';
import {useLocation} from "@umijs/max";
const location = useLocation();
const queryParams = parse(window.location.search);
React.useEffect(() => {
if(Object.keys(queryParams).length>0){
formRef.current?.setFieldsValue(queryParams)
}, []);