Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 打开modal、ReactJS后更新URL_Javascript_Reactjs_Url_React Router_Modal Dialog - Fatal编程技术网

Javascript 打开modal、ReactJS后更新URL

Javascript 打开modal、ReactJS后更新URL,javascript,reactjs,url,react-router,modal-dialog,Javascript,Reactjs,Url,React Router,Modal Dialog,我有点新的反应,我想改变url一旦用户点击打开一个模式窗口。还有一些数据随模式而来,我想在url中反映出来。例如,“我的应用程序/文件夹/项目名称/” 我尝试了一些反应路由器的解决方案,但我似乎没有得到它只是正确的 这是一个模式,我希望在URL打开后可以更新它 {modalOpen ? ( <ProjectModal projectName={target[0].project_name} organization={target[0].organizati

我有点新的反应,我想改变url一旦用户点击打开一个模式窗口。还有一些数据随模式而来,我想在url中反映出来。例如,“我的应用程序/文件夹/项目名称/”

我尝试了一些反应路由器的解决方案,但我似乎没有得到它只是正确的

这是一个模式,我希望在URL打开后可以更新它

{modalOpen ? (
    <ProjectModal
      projectName={target[0].project_name}
      organization={target[0].organization}
      avatar={target[0].organization_avatar}
      client="xy"
      selectedImg={target[0].images[0]}
      gallery={target[0].images}
      onClose={() => setModalOpen(false)}
    />
  ) : null}
{modalOpen(
setModalOpen(假)}
/>
):null}

确保路由器中提到了此路由。像这样的,

<Route path="parent" component="ParentComponent" />
<Route path="parent/modal" component="ParentComponent" />

然后,在设置变量以打开模式时,必须使用history.push方法

history.push('/parent/modal')

希望我的回答有帮助


查看以获取更多信息。

确保路由器中提到了此路由。像这样的,

<Route path="parent" component="ParentComponent" />
<Route path="parent/modal" component="ParentComponent" />

然后,在设置变量以打开模式时,必须使用history.push方法

history.push('/parent/modal')

希望我的回答有帮助

有关更多信息,请查看