在响应中的 url 更改上重新渲染相同的组件 [英] Re-render same component on url change in react

查看:23
本文介绍了在响应中的 url 更改上重新渲染相同的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个路由,它接受一个 id 并为每个 id 呈现相同的组件,例如:

I have a route which takes an id and renders the same component for every id, for example : <Route path='/:code' component={Card}/>

现在在 Link 标签中,我将 id 传递给组件.现在 Card 组件根据传递的 id 获取其他详细信息.但问题是它只为一个 id 呈现,如果我单击返回并转到下一个 id,则不会更新.我搜索并发现可以使用 componentsWillReceiveProps 但在 React 的最新版本中它已被弃用.那么如何做到这一点呢?

Now the in the Link tag I pass in an id to the component.Now the Card component fetches additional detail based on the id passed. But the problem is it renders only for one id and is not updating if I click back and goto the next id. I searched and found out that componentsWillReceiveProps can be used but during recent versions of React it has been deprecated. So how to do this?

推荐答案

在 React Router v4 中在 Router 修复问题后添加 Switch 标签

In React Router v4 Adding a Switch tag after Router fixes the problem

这篇关于在响应中的 url 更改上重新渲染相同的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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