重新呈现URL响应中的相同组件 [英] Re-render same component on url change in react

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

问题描述

我有一条路由,该路由带有一个id,并为每个id呈现相同的组件,例如:<路由路径='/:code'组件= {Card}/>

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中,在路由器解决问题后添加Switch标签

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

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

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