我是个反应迟钝的新手。我按照教程React Tutorial创建了一个注册表。但话说回来,它已经过时了。我试图重定向到注册,登录和主页上点击链接使用浏览器重定向。本教程定义的路由如下
const routes = {
component: Base,
childRoutes: [
{
path: '/',
component: HomePage
},
{
path: '/login',
component: LoginPage
},
{
path: '/signup',
component: SignUpPage
}
]
};基本组件定义了带有链接的导航栏。然后将此路由导入到索引页,并与浏览器历史一起使用,根据React Router v4,浏览器历史已过时。我想使用Browser Router,但我不知道如何提供附加了组件的子路由。
我尝试了以下几种方法
Index.jsx
import { BrowserRouter as Router,Route } from 'react-router-dom';
ReactDOM.render((
<MuiThemeProvider muiTheme={getMuiTheme()}>
<Router>{routes}</Router>
</MuiThemeProvider>),
document.getElementById('root')
);Routes.jsx
const routes = <Route component = {Base}>
<Switch>
<Route path="/" component={HomePage}/>
<Route path ="/login" component = {LoginPage}/>
<Route path ="/signup" component = {SignUpPage}/>
</Switch>
</Route>;但我从一开始就知道这不会起作用,不出所料,它抛出了一个错误。You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored和失败的属性类型:The propchildrenis marked as required inBase, but its value isundefined.这是显而易见的,因为我在任何地方都没有像以前的版本那样提到子路由。我也尝试过查看此React training link,但可以找到将组件插入到路由的位置。
如果这个问题已经被问到了,我很抱歉,但是我找不到很多关于react路由器4的教程或适当的文档来帮助我。
发布于 2017-07-20 23:48:23
我认为你应该删除<Route component = {Base}>,改用<Base>
https://stackoverflow.com/questions/45219156
复制相似问题