App.js
<ConnectedRouter history={history}>
<Switch>
<Route path="/dashboard" name="Layout" component={Layout} />
<Route exact path="/login" name="Login" component={Login} />
<Redirect from="/" to="/dashboard" />
<Route component={NoMatch}/>
</Switch>
</ConnectedRouter>Layout.js
<Switch>
<Route path="/" name="Dashboard" component={Dashboard} />
<Route path="/components/a" component={ComponentA} />
<Route path="/components/b" component={ComponentB} />
</Switch>
更新:将重定向更改为<Route exact path='/' render={() => <Redirect to='/dashboard' />} />可以修复问题#2,但问题#1仍然存在
发布于 2017-07-05 08:04:57
当您键入导航到Route或/dashboard/componenets/b时,您可能也需要更改您的/dashboard/componenets/a路径以具有一个/dashboard参数。
<Switch>
<Route exact path="/dashboard" name="Dashboard" component={Dashboard} />
<Route path="/dashboard/components/a" component={ComponentA} />
<Route path="/dashboard/components/b" component={ComponentB} />
</Switch>https://stackoverflow.com/questions/44919666
复制相似问题