【问题标题】:Update URL after opening modal, ReactJS打开模式后更新 URL,ReactJS
【发布时间】:2020-12-05 12:41:15
【问题描述】:

我有点新反应,一旦用户单击打开模式窗口,我想更改 url。还有一些我想在 url 中反映的模态数据。例如。 "my.app/folders/project-name/"

我尝试了一些反应路由器的解决方案,但我似乎没有得到它恰到好处...

这是我希望一旦打开 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}

【问题讨论】:

    标签: javascript reactjs url react-router modal-dialog


    【解决方案1】:

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

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

    那么你将不得不使用 history.push 方法同时设置变量来打开模态。

    history.push('/parent/modal');

    希望我的回答有帮助。

    查看docs 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 2014-04-02
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      相关资源
      最近更新 更多