在 react-router-dom Link 中传递参数无法正常工作
pass parameters in react-router-dom Link not woking fine
我正在尝试在 react-router-dom Link 中传递参数,但不确定为什么它每次都不起作用。有时工作正常,有时单击它时什么也没有发生(devtool 中没有错误)。
我一开始就有 import Link , import { Link } from "react-router-dom";
谁能帮我吗?谢谢
constructor(props){
super(props);
this.state = {
pageNumber: 1,
pageSize: 10,
keyWork:"",
// modal: cancel notification
visible:false,
doctorID:"",
// table header
columns:[
{title:"Doctor Photo", dataIndex:"picUrl", key:"picUrlMenu", width:70, fixed: 'left',
render: picUrl => <Image className="doctorPhoto" style={{ height: 50, width:50 }} alt={picUrl} src={picUrl}/>
},
{title:"DoctorID", dataIndex:"doctorID", key:"doctorIdMenu", width:70, fixed: 'left',responsive: ['md'],
defaultSortOrder: 'descend',
sorter: (a, b) => a.doctorID - b.doctorID,
},
{title:"Management", dataIndex:"management", key:"management", width:200, fixed: 'right',
render:(text, rowData) =>{
return(
<div>
<Button className="planButton" type="primary" icon={<SnippetsOutlined />}>
<Link
to={{
pathname: "/index/plan",
state:{doctorid: rowData.doctorID}}}>,
</Link>
Plan
</Button>
<Popover content={content} >
<Button className="delDoctorButton" icon={<DeleteOutlined />} onClick={()=>this.delDoctor(rowData.doctorID)} >Delete</Button>
</Popover>
</div>
)
}
}
],
// tabel data
data:[],
};
}
最后我发现代码没有问题,现在 link 只有在点击文本“计划”时才有效,所以如果你想在点击按钮时重定向,只需移动 Link 到按钮,像这样:
我正在尝试在 react-router-dom Link 中传递参数,但不确定为什么它每次都不起作用。有时工作正常,有时单击它时什么也没有发生(devtool 中没有错误)。 我一开始就有 import Link , import { Link } from "react-router-dom"; 谁能帮我吗?谢谢
constructor(props){
super(props);
this.state = {
pageNumber: 1,
pageSize: 10,
keyWork:"",
// modal: cancel notification
visible:false,
doctorID:"",
// table header
columns:[
{title:"Doctor Photo", dataIndex:"picUrl", key:"picUrlMenu", width:70, fixed: 'left',
render: picUrl => <Image className="doctorPhoto" style={{ height: 50, width:50 }} alt={picUrl} src={picUrl}/>
},
{title:"DoctorID", dataIndex:"doctorID", key:"doctorIdMenu", width:70, fixed: 'left',responsive: ['md'],
defaultSortOrder: 'descend',
sorter: (a, b) => a.doctorID - b.doctorID,
},
{title:"Management", dataIndex:"management", key:"management", width:200, fixed: 'right',
render:(text, rowData) =>{
return(
<div>
<Button className="planButton" type="primary" icon={<SnippetsOutlined />}>
<Link
to={{
pathname: "/index/plan",
state:{doctorid: rowData.doctorID}}}>,
</Link>
Plan
</Button>
<Popover content={content} >
<Button className="delDoctorButton" icon={<DeleteOutlined />} onClick={()=>this.delDoctor(rowData.doctorID)} >Delete</Button>
</Popover>
</div>
)
}
}
],
// tabel data
data:[],
};
}
最后我发现代码没有问题,现在 link 只有在点击文本“计划”时才有效,所以如果你想在点击按钮时重定向,只需移动 Link 到按钮,像这样: