【发布时间】:2018-09-10 17:27:38
【问题描述】:
我正在寻找这个,但我找不到正确的答案。是否可以在 React Component 中像这样使用 React Router;
import { Route, Switch } from 'react-router'
import LandingLayout from '../../layouts/landing/LandingLayout'
import AppLayout from '../../layouts/app/AppLayout'
<Switch>
<LandingLayout>
<Route path="/" exact="true" component={Home} />
<Route path='/login' component={Login} />
<Route path='/signup' component={Signup} />
</LandingLayout>
<AppLayout>
<Route path='/dashboard' component={DashboardPage} />
<Route path='/users' component={UserList} />
<Route path='/u/:username' component={AccountPage} />
</AppLayout>
<Route component={NotFound} />
</Switch>
【问题讨论】:
-
你有什么错误吗?
-
首先,在“/dashboard”或“/users”路由页面自带Landing Layout,必须将App Layout和中间的content section渲染为空。但在“/”主页或登录页面上,它会正确呈现。
-
server.js 也记录了这一点。警告:失败的道具类型:提供给
Route的string类型的无效道具exact,应为boolean。在 Route 中 Routes 中 Router 中 StaticRouter 中 Provider 中 LocaleProvider
标签: reactjs react-router-v4 react-component