在更新了我们的一堆依赖项之后,我们现在被迫使用导致重定向的锚标记,在我们使用之前但现在每次我们点击它都会转到正确的 url 即 /screens 但它只是一个空白页面并且从不显示组件,下面是我们的父 index.tsx 文件:ReactDOM.render( <Provider {...stores}> {/* Changed routes to children */} {/* <Router children={routes} history={createHistory} /> */} <Router history={createHistory}> <div> <Switch> <Route path='/oauth2callback' componentDidMount={console.log()}> {() => { if(window.location.href.includes('/oauth2callback')) { oauth2callback(window.location.hash) } }} </Route> <Route path='/testing' component={Get} /> <Route path='/'> {/* Function that determines if the user is logged in and can allow the authenticated passage or not. If no, it will not render authenticated pages*/} {() => { if(auth.loggedIn()) { console.log("is logged in") return( <div> <Route component={App} history={createHistory}/> <div className="row" id="wrapper"> <Switch> {/* <Route path='/screens' component={Screens}/> */} <Route path='/screens' component={Screens}/> <Route path='/playlists' component={Playlists}/> <Route path='/content' component={Content}/> <Route path='/help' component={HelpNav}/> <Route component={NotFound}/> </Switch> </div> </div> ) }知道新的反应路由器更新有什么不同导致这个错误存在吗?
2 回答

慕神8447489
TA贡献1780条经验 获得超1个赞
修复比我想象的要简单得多,新的更新集成了 BrowserRouter 而不是 Router 所以我更换了
<Router history={createHistory}>
和
<BrowserRouter>
现在一切正常

手掌心
TA贡献1942条经验 获得超3个赞
在这篇 React Router 6 文章https://medium.com/frontend-digest/whats-new-in-react-router-6-732b06cc83e4上阅读“路由和链接相对于它们的父级”
顺便说一下,有时你有<a>
标签而不是链接组件很奇怪
添加回答
举报
0/150
提交
取消