Javascript 如果用户使用不同的查询从组件的url导航到同一url,如何强制路由重新提交其组件

Javascript 如果用户使用不同的查询从组件的url导航到同一url,如何强制路由重新提交其组件,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我有这个组件,在我尝试从组件的URL导航到同一个URL,但使用不同的查询参数之前,它工作得非常好。这使得组件不会重新安装自身,从而与逻辑发生冲突。我想知道是否有可能使组件完全重新安装自己 我的路线如下所示: <Route exact path={`${match.url}configuration/beds-carts/non-uhe-units`} component={NonUheUnits} /> <Menu.Item key="con

我有这个组件,在我尝试从组件的URL导航到同一个URL,但使用不同的查询参数之前,它工作得非常好。这使得组件不会重新安装自身,从而与逻辑发生冲突。我想知道是否有可能使组件完全重新安装自己

我的路线如下所示:

<Route
    exact
    path={`${match.url}configuration/beds-carts/non-uhe-units`}
    component={NonUheUnits}
/>
<Menu.Item key="configuration/beds-carts/non-uhe-units">
  <Link to={`/configuration/beds-carts/non-uhe-units?sort=${encodeURIComponent('organization,asc')}`}></Link>
</Menu.Item>
http://localhost:3000/configuration/beds-carts/non-uhe-units?sort=customer%2Casc&sort=facility%2Casc&sort=organization%2Casc
因此,当我进入这一页并进行排序时,我可能会得到如下结果:

<Route
    exact
    path={`${match.url}configuration/beds-carts/non-uhe-units`}
    component={NonUheUnits}
/>
<Menu.Item key="configuration/beds-carts/non-uhe-units">
  <Link to={`/configuration/beds-carts/non-uhe-units?sort=${encodeURIComponent('organization,asc')}`}></Link>
</Menu.Item>
http://localhost:3000/configuration/beds-carts/non-uhe-units?sort=customer%2Casc&sort=facility%2Casc&sort=organization%2Casc

我想被发送到
http://localhost:3000/configuration/beds-carts/non-uhe units?sort=organization%2Casc
当我单击
元素时,组件中的现有逻辑对URL做了一些更改,但结果不是这样。我想完全重新安装该组件,以便在单击
时清除所有以前保存的状态/道具/查询。可以这样做吗?

组件在componentDidUpdate方法中重新装载。只需将整个组件包装在withRouter中,如果prevProps.router.query与此不同,请检查componentDidUpdate方法,如果是,请执行您必须执行的操作。(我不确定它是路由器还是历史记录,请查看有关如何在react router中获取URL查询参数的文档,但我就是这样做的)