我正在使用 React Router Dom 和 BrowserRouter 对象为我正在构建的站点启用基于浏览器的导航.导航运行良好,但如果用户点击后退按钮,我应用的整个状态都会被清除.
I'm using React Router Dom and the BrowserRouter object to enable browser based navigation for a site I'm building. Navigation works well, but if a user hits the back button, the entirety of my App's state is wiped clean.
我不确定为什么会发生这种情况.我试过四处寻找,但我找到的所有答案都没有提到应用程序状态重置的原因.
I'm not sure why this is happening. I've tried searching around, but all of the answers I've found don't mention why App state is getting reset.
这是我的实现:
<BrowserRouter> <Switch> <Route path="/" exact render={()=><LandingPage/>} <Route path="/about" render={()=><About/>} </Switch> </BrowserRouter>我做错了什么吗?任何有使用 React Router 经验的人都可以给我一些建议吗?非常感谢!
Am I doing something glaringly wrong? Could anyone with experience working with React Router give me some advice? Thanks so much!
推荐答案如果像我这样的人将来遇到这个问题并且从 Google 来到这里,这是发生了什么:
If someone like me has this problem in the future and comes here from Google, here's what's going on:
感谢@charlietfl 提供的信息.
Thanks @charlietfl for the info.
更多推荐
React Router + 后退按钮正在重置我的应用程序状态
发布评论