我是个新手,我想在用户点击打开模式窗口后更改url。还有一些模态附带的数据,我想在url中反映出来。例如";my.app/folders/project-name/";
我尝试了一些react路由器的解决方案,但我似乎做得不太好。。。
这是我希望在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}
确保路由器中提到了此路由。像这样的
<Route path="parent" component="ParentComponent" />
<Route path="parent/modal" component="ParentComponent" />
然后,在设置变量以打开模态时,必须使用history.push方法。
history.push('/parent/modal');
希望我的回答能有所帮助。
查看文档以了解更多信息。