Reactjs 当另一条路由在react路由器中处于活动状态时,如何禁用特定路由
我有两个组成部分:体育和娱乐。我希望当我的运动路线处于活动状态时,用户不应访问娱乐路线。我该怎么做 我的App.js文件中的路由代码Reactjs 当另一条路由在react路由器中处于活动状态时,如何禁用特定路由,reactjs,react-router,react-router-dom,react-router-v4,Reactjs,React Router,React Router Dom,React Router V4,我有两个组成部分:体育和娱乐。我希望当我的运动路线处于活动状态时,用户不应访问娱乐路线。我该怎么做 我的App.js文件中的路由代码 <Router> <Switch> <Route path="/" exact> <Redirect to="/home" /> </Route> <Route path="/home" compon
<Router>
<Switch>
<Route path="/" exact>
<Redirect to="/home" />
</Route>
<Route path="/home" component={Main} />
<Route path="/sports" component={Sports} />
<Route path="/entertainment" component={Entertainment} />
</Switch>
</Router>
您可以分为两个部分 举个例子:
const Routers = () => {
const toggleRoutesPermission = true // should get the permission value from somewhere
return (
<Router>
<Switch>
<Route path="/" exact>
<Redirect to="/home" />
</Route>
<Route path="/home" component={Main} />
{
toggleRoutesPermission
? <Route path="/sports" component={Sports} />
: <Route path="/entertainment" component={Entertainment} />
}
</Switch>
</Router>
)
}
const路由器=()=>{
const-toggleRoutesPermission=true//应该从某处获取权限值
返回(
{
切换路由许可
?
:
}
)
}
mybe这对您有帮助吗