我想在登录页面中隐藏导航栏.
我实际上做到了,但我看不到其他页面的导航栏.
此代码是My App.jsx文件的一部分.
我在App的状态下创造了历史.当这个路径名为'/'或'/ login'时,我会隐藏导航栏.
有用!
但是我输入了id和密码,然后点击登录按钮,得到"成功"结果,导航到'/ main'.
我也看不到主要组件中的导航栏.
我该怎么办?请帮我.
抱歉我的英文短文.如果你无法理解我的问题,你可以发表评论.
constructor(props) {
super(props);
this.state = {
isAlertOpen: false,
history: createBrowserHistory(),
};
this.toggleAlert = this.toggleAlert.bind(this);
}
<BrowserRouter>
<div className="App">
{this.state.history.location.pathname === '/' || this.state.history.location.pathname === '/login' ? null
: <Header toggleAlert={this.toggleAlert} />}
<div className="container">
{this.state.history.location.pathname === '/' || this.state.history.location.pathname === '/login' ? null
: <Navbar />}
<Route exact path="/" render={() => <Redirect to="/login" />} />
<Route path="/login" component={Login} />
<Route path="/main" component={Main} />
<Route path="/user" component={User} />
<Route path="/hw-setting" …Run Code Online (Sandbox Code Playgroud)