我正在努力实现这个目标。我已经到处搜索解决方案,但无法使其正常工作。
我在一个名为routes.jsx的单独文件中定义了我的路由,
在我的应用程序上,我正在导入我的路线和我的导航,这部分是可以的
但我的问题是,导航,当我点击,回家或者例如,浏览器把我带到那里,但是身体的内容没有更新,所以例如,当我点击导航链接时,我不知道在体内看到,我必须刷新浏览器才能看到它......
这是因为你使用两个独立的<BrowserRouter>
s。它应该位于组件层次结构的最高级别。我会从Routes
和Nav
中删除它并用它启动<App>
class App extends React.Component {
render() {
return (
<BrowserRouter>
....
</BrowserRouter>
);
}
}