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 仍然是
答案 0 :(得分:0)
当您要导航到Route
或/dashboard
时,您可能需要更改/dashboard/componenets/a
路径以获得/dashboard/componenets/b
参数
<Switch>
<Route exact path="/dashboard" name="Dashboard" component={Dashboard} />
<Route path="/dashboard/components/a" component={ComponentA} />
<Route path="/dashboard/components/b" component={ComponentB} />
</Switch>