关于未解决的问题(作为最终结论)
我也遇到了同样的问题。
https://reacttraining.com/react-router/web/guides/quick-start推广react-router-dom
此外,人们发现list down routes
在一个文件中而不是在组件中更好。
提到的东西: https ://github.com/ReactTraining/react-router/tree/master/packages/react-router-config
一些工作(大部分):
import * as React from 'react'
import {BrowserRouter as Router, Route, Switch } from 'react-router-dom'
export const Routes = () => (
<Router>
<div>
<Switch>
<Route exact path="/login" component={Login}/>
<MainApp path="/">
<Route path="/list" component={List}/>
<Route path="/settings" component={Settings}/>
</MainApp>
<Route path="*" component={PageNotFound}/>
</Switch>
</div>
</Router>
)
有些东西不起作用:
site.com/SomeGarbagePath
显示<MainApp>
我的想法。
<Route path="*" component={PageNotFound}/>
更新
/ - Home - parent of all (almost)
/List - inside home
/Settings - inside home
/Login - standalone
/Users - inside home, For now just showing itself. It has further pages.
/User/123 - inside user with /:id
/User/staticUser - inside user with static route
/garbage - not a route defined (not working as expected)