反应:URL 配置文件 ID 不匹配(match.params.id) [英] React: URL Profile ID doesn't match (match.params.id)

查看:44
本文介绍了反应:URL 配置文件 ID 不匹配(match.params.id)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以每当我点击查看个人资料链接

So whenever I clicked the View Profile Link

 <Link to={`/profile/${_id}`} className="btn btn-primary">
                View Profile
 </Link>

它会在 URL 中显示好的配置文件的用户 ID.

It shows in the URL the User ID of the Profile which is Good.

但是每当我单击它以将其与此按钮匹配时,我都会收到错误消息.

But whenever I Clicked it to Match it with this Button I get an error.

const Profile = ({ getProfileById, match }) => {
useEffect(() => {
    getProfileById(match.params.id);
}, [getProfileById]);

return <div>test</div>;

};

我进入我的控制台

React Hook useEffect has a missing dependency: 'match.params.id'. Either include it or remove the dependency array

这就是我的应用 Js 中的内容.

this is what is in my app Js.

   <Route
         exact
         path="/profile/:id"
         component={Profile}
     />

我认为它与我点击的按钮的 URL 不匹配.

I think it doesn't match with the URL to the button I clicked.

在 Redux Devtools 中,它只返回配置文件错误.

and inside the Redux Devtools it only returns a Profile Error.

推荐答案

我设法找出问题所在.它在我的 API 中.我试图在我的 API 中点击 .get

I managed to figure out what's wrong. It's in my API. I am trying to hit the .get in my API

但在我的 API 中,它指示了补丁.

But inside my API it is indicated the patch.

我改变了它以获得.

它有效.

这篇关于反应:URL 配置文件 ID 不匹配(match.params.id)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆