将所有路由重定向到页面

问题描述 投票:0回答:2

我有很多这样的路线

<Switch>
<Route path="/dashboard"   component={Dashboard}     key="dashboard" />
<Route path="/projects"    component={UserProjects}  key="userprojects" />
<Route path="/compute/servers" component={ProjectServerList}   key="projectserverlist" />
<Route path="/compute/snapshots"  component={ServerSnapshotList}  key="ServerSnapshotList" />
<Route path="/compute/keypairs"   component={KeypairList}         key="KeypairList" />

它们工作正常,但是如果没有设置属性,我希望将它们全部重定向到'/ dashboard']

我尝试过这个:

{myproperty ?
<Switch>
<Route path="/dashboard"   component={Dashboard}     key="dashboard" />
</Switch>
:
<Switch>
<Route path="/dashboard"   component={Dashboard}     key="dashboard" />
<Route path="/projects"    component={UserProjects}  key="userprojects" />
<Route path="/compute/servers" component={ProjectServerList}   key="projectserverlist" />
<Route path="/compute/snapshots"  component={ServerSnapshotList}  key="ServerSnapshotList" />
<Route path="/compute/keypairs"   component={KeypairList}         key="KeypairList" />
  </Switch>
}

并且失败失败

我正在使用“ react-router-dom”:“ ^ 4.3.1”,“ react-router-redux”:“ ^ 5.0.0-alpha.9”,“反应”:“ ^ 16.13.1”,

我有很多这样的路由

reactjs react-router-dom react-router-v4 react-router-redux
2个回答
1
投票

简单,干净且可重用-


0
投票

我做了一些修改,希望它是您想要的

© www.soinside.com 2019 - 2024. All rights reserved.