1 回答

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>
添加回答
舉報