第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

具有不同頁面布局的嵌套反應(yīng)路線

具有不同頁面布局的嵌套反應(yīng)路線

紅顏莎娜 2021-10-14 16:53:20
我的代碼有兩個問題:第一:我的整個應(yīng)用程序似乎運行良好,當(dāng)我第一次加載我的 Web 應(yīng)用程序時,我可以訪問我的所有路由。我的應(yīng)用程序包含一個帶有導(dǎo)航欄的登陸頁面,導(dǎo)航欄有一個登錄按鈕,可將我直接帶到應(yīng)用程序的主頁(尚未添加身份驗證)。此主頁的導(dǎo)航欄與登錄頁面上的導(dǎo)航欄不同。導(dǎo)航欄項目是(home、about 和 LandingPage)。我的 App.js 有到登陸頁面組件、作為 Gitapp 組件的主頁和一個 PageNotFound 組件的路由。Gitapp 組件包含到關(guān)于頁面和其他組件的路由。如果我在 App.js 上的其中一個路由(第一級路由)上碰巧重新加載頁面,它會重新加載正常。但是,如果我在 Gitapp 組件上存在的路由(二級路由)上,第二:我的第二個導(dǎo)航欄有一個退出按鈕,可以讓我回到登陸頁面。由于某種原因,我無法讓它工作,因為如果我將路由添加到我的 Gitapp 組件中的登錄頁面,React 將嘗試在主頁下方顯示登錄頁面。這是 App.js:const App = () => {  return (    <Fragment>      <Router>        <Switch>          <Route exact path='/' component={LandingPage} />          <Route exact path='/gitapp' component={GitApp} />          <Route component={PageNotFound} />        </Switch>      </Router>    </Fragment>  );};這是 LandingPage.js:const LandingPage = () => {  return (    <div>      <NavbarLanding />      <SideNavBar />      <LandingSection1 />      <LandingSection2 />      <LandingSection3 />      <Route exact path='/gitapp' component={GitApp} />    </div>  );};這是 Gitapp.js:const GitApp = ({ match }) => {  return (    <GithubState>      <Router>        <div style={containerStyling}>          <Navbar />          <Switch>            <Route exact path={match.url} component={Home} />            <Route              exact              path={`${match.url}/user/:login`}              component={UserProfile}            />            <Route exact path={`${match.url}/about`} component={About} />          </Switch>          <Footer />        </div>      </Router>    </GithubState>  );};const containerStyling = {  minHeight: '100vh',  overflow: 'hidden',  display: 'block',  position: 'relative',  paddingBottom: '70px'};
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻1875條經(jīng)驗 獲得超5個贊

我已經(jīng)解決了這兩個問題!我不得不去掉 App.js 中定義的 Gitapp 路由中的“精確”這個詞。所以而不是:


const App = () => {

  return (

    <Fragment>

      <Router>

        <Switch>

          <Route exact path='/' component={LandingPage} />

          <Route exact path='/gitapp' component={GitApp} /> {/* Wrong! */}

          <Route component={PageNotFound} />

        </Switch>

      </Router>

    </Fragment>

  );

};

它應(yīng)該是:


const App = () => {

  return (

    <Fragment>

      <Router>

        <Switch>

          <Route exact path='/' component={LandingPage} />

          <Route path='/gitapp' component={GitApp} /> {/* Correct! */}

          <Route component={PageNotFound} />

        </Switch>

      </Router>

    </Fragment>

  );

};

不知道為什么,但我可以重新加載二級組件而不是接收 NotFound 組件。如果有人能解釋為什么精確這個詞在這里有所不同,我們將不勝感激。


至于我的第二個問題,我只是使用了條件渲染的重定向。因此,我的上下文 api 將更新我的全局“注銷”狀態(tài)并將其傳遞給組件,然后組件將等待它(“注銷”狀態(tài))變?yōu)檎?,然后將我重定向到登錄頁面?/p>


查看完整回答
反對 回復(fù) 2021-10-14
  • 1 回答
  • 0 關(guān)注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號