0
<Router history={history}>
<Switch>
<Route exact path="/" render={() => (
AUTH ? (
AUTH == "1" ?
<NormalPage />
:
<AdminPage />
) : (
<Redirect to="/login" />
)
)} />
<Route exact path="/login" component={LoginPage} />
</Switch>
</Router>
我寫這樣的代碼。當AUTH未定義時,頁面將重定向到登錄頁面。 但是當我登錄時,我應該在登錄頁面中編寫代碼,我想回到主頁。現在,當我登錄時,我使用window.location.href =「/」返回主頁。但我認爲這是不好的方法。提示:我的第一語言不是英語,所以對不起:D當我登錄時,如何重定向到react-router中的主頁?