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中的主页?