App.js反應路由器4 - 嵌套switch預期
<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>
- 問題不起作用:
- 問題#1導航到「/dashboard/components/a'或'/ dashboard/components/b'不按預期顯示組件a或b
- 問題#2導航到錯誤的路徑總是重定向到 '/儀表盤' 不顯示NOMATCH部件
UPDATE: 改變重定向到 <Route exact path='/' render={() => <Redirect to='/dashboard' />} />
可以修復問題#2但問題#1仍然
嘗試使用'<重定向從= '/' 來= 「/組件/一個」/>'後'<路由路徑=「/ components/a「component = {ComponentA} />' –
嘗試在您的路線上放置'exact'? – Winter