首页 > 解决方案 > 修复了更改用户的个人资料页面时不会重新渲染的组件

问题描述

const Profile = () => {
 return(
   <div>
     <ProfileData/>
     <Switch>
       <Route exact path="/profile/:user" component={(props) => (<ProfileScreen {...props}/>)}/>
       <Route exact path="/profile/:user/followers" component={(props) => (<ProfileFollowers {...props}/>)}/>
       <Route exact path="/profile/:user/following" component={(props) => (<ProfileFollowing {...props}/>)}/>
       <Route component={NotFound}/>
     </Switch>
   </div>
 )
}

因此,在上述路线中,我有一个组件 ProfileData,其中包含有关用户的名称和其他一般信息。在浏览用户的关注者和关注者时,此组件不会重新呈现,但现在当我在关注者部分(使用 NavLink)单击用户时,上述 ProfileData 不会重新呈现并包含有关前一个用户的信息。解决此问题的最佳方法是什么,以便在导航到另一个用户的个人资料页面时重新呈现 ProfileData?

标签: javascriptreactjsreact-routercomponents

解决方案


推荐阅读