微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

即使URL包含参数,match.params也将返回空

如何解决即使URL包含参数,match.params也将返回空

当我单击预订的特定ID时,我想在表单上进行编辑,以便将ID中的值传递到编辑表单中。但是,即使URL包含参数,match.params也会返回空。我该如何解决

这是我编辑的预订文件

export default function Adminedit(props) {
    const [CategoryList,setCategory] = useState([]);
    const [data,setData] = useState({
        date: "",firstName: "",lastName: "",phone: "",email: "",nopersons: "",time: "",});

    useEffect(() => {
        const _id = props.match.params.id;
        console.log(props.match.params.id);
        console.log(_id);

        Axios.get(config.API_HOST_ORIGINAL + `/adminbookings/` + _id,{
            headers: {
                'Authorization': 'Bearer ' + config.getToken()
            }
        }).then(res => {
            setData(res.data)
            console.log("Logged res data:",res.data);

        }).catch(err => console.error(err))
    },[]);

    function submit(e) {
        e.preventDefault();
        Axios.post(config.API_HOST_ORIGINAL + '/bookings/',{
            headers: {
                'Authorization': 'Bearer ' + config.getToken()
            }
        }).then(res => {
            console.log(res.data);
            const myData = [...CategoryList,res.data]
            setCategory(myData)
        }).catch(err => console.error(err))
    }

    function handle(e) {
        const newData = { ...data }
        newData[e.target._id] = e.target.value;
        setData(newData);
    }


**Another other file:
This is where I take in all the bookings**

const Bookings = (props) => {
Some hooks...

  function Update(_id) {
    console.log("Log this shiiiet to console",_id);
    props.history.push("/adminedit/" + _id);
  }

return {
<>
    <td>
        <button type="button" 
        onClick={() => Update(bookings._id)} 
         className="btn btn-primary btn-sm">Edit</button>
     </td>
</>
}

export default Bookings;

Recives this warning!

解决方法

您应该使用<svg width='200' height='200'> <filter id='blur' width='100%' height='100%'> <feGaussianBlur stdDeviation='2' result='blur' /> </filter> <image x='0' width='200px' height='200px' xlink:href='' id='svg-image' filter='url(#blur)' /> </svg>中的useParams钩子。

您还应该在react-router-dom之外定义id

useEffect

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。