我有很多这样的路线
<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”,
我有很多这样的路由
我做了一些修改,希望它是您想要的