亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React Router 在使用 <Link> 時顯示空白頁面

React Router 在使用 <Link> 時顯示空白頁面

慕娘9325324 2022-12-22 10:07:16
在更新了我們的一堆依賴項之后,我們現在被迫使用導致重定向的錨標記,在我們使用之前但現在每次我們點擊它都會轉到正確的 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>

現在一切正常


查看完整回答
反對 回復 2022-12-22
?
手掌心

TA貢獻1942條經驗 獲得超3個贊

在這篇 React Router 6 文章https://medium.com/frontend-digest/whats-new-in-react-router-6-732b06cc83e4上閱讀“路由和鏈接相對于它們的父級”

順便說一下,有時你有<a>標簽而不是鏈接組件很奇怪


查看完整回答
反對 回復 2022-12-22
  • 2 回答
  • 0 關注
  • 90 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號