在刷新页面之前切换页面时,Flowbite Modal 不会打开

Flowbite Modal does not open when switching between pages until you refresh the page

在移动设备屏幕上,第一次加载页面并单击按钮打开模式时,它确实打开了,但是在您转到另一个页面并尝试打开另一个模式后,它没有打开,您应该刷新每次您转到另一个页面时都会一次又一次地打开该页面。enter image description here

您必须在代码中使用“useState”来管理打开或关闭模式的情况,如下所示:

const Main = ()=>{
const [visible,setVisible]=useState(false)

return(
<>
<button onClick={()=>setVisible(true)}>Open Modal</button>
<Modal visible={visible} ... />
</>
}

在您的模态中,您必须检查 props(visible) 的值,然后在单击 onClose 时显示模态是否也定义了 setVisible(false)。