【发布时间】:2021-01-29 23:55:35
【问题描述】:
因为我是 ReactJS 的新手。我尝试了许多解决方案来在不同组件上实现显示/隐藏侧边菜单。
要求是:
一个。当用户登录后,所有组件都会显示侧边菜单。
b.当用户注销时,它只显示一些组件,如忘记密码或条款和条件(菜单名称根据身份验证更改),但隐藏在登录组件上。
App.js
<Router>
<SideNavigation />
<Routes />
</Router>
Routes.js
<Switch>
<Route exact path="/login" component={Login} />
<Route exact path="/forgotPassword" component={ForgotPassword} />
<Route exact path="/termAndCondition" component={TermAndCondition} />
<PrivateRoutes exact path="/" component={Dashboard} />
<PrivateRoutes exact path="/emp" component={Employee} />
<PrivateRoutes exact path="/empList" component={EmployeeList} />
</Switch>
【问题讨论】:
-
这可能会有所帮助,请检查simple-conditional-routing-in-reactjs
-
嗨@NooruddinLakhani ....感谢您的回复.........我的情况有所不同...当用户登录但当用户登录时,我必须显示侧面导航注销然后我必须仅从登录页面隐藏侧面导航并在忘记密码页面上显示....在这种情况下,它会从忘记密码页面隐藏侧面导航...这实际上并不是要求...... ......谢谢
标签: javascript reactjs react-native react-router router