警告:失败的道具类型:提供给路由器

时间:2017-02-25 17:39:33

标签: reactjs react-router

我遗漏了一些非常基本的东西。 - 我试图实现react-router。我在页面加载时遇到错误:

Warning: Failed prop type: Invalid prop 'children' supplied to 'Router'.
    in Router

此外,配置的路线似乎没有被正确拾取 例如Warning: [react-router] Location "/policies" did not match any routes 我已经看了一下,但似乎没有什么与我所拥有的相关。

我做错了什么?

index.js

import 'core-js/fn/object/assign';
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, IndexRoute, hashHistory, browserHistory } from 'react-router';
import {Dashboard} from './components/Main';
import {OverviewComponent} from './components/dashboard/OverviewComponent';
import {PoliciesComponent} from './components/dashboard/PoliciesComponent';
import {ReportingComponent} from './components/dashboard/ReportingComponent';

// Render the main component into the dom
//ReactDOM.render(<App />, document.getElementById('app'));
ReactDOM.render((
  <Router history={browserHistory}>
    <Route path="/" component={Dashboard}>
        <Route path="/policies" component={PoliciesComponent} />
        <Route path="/reports" component={ReportingComponent} />
    </Route>
  </Router>),
 document.getElementById('app')); 

摘自Main.js

import React from 'react';
import { Link } from 'react-router';
import {OverviewComponent} from './dashboard/OverviewComponent';
import {PoliciesComponent} from './dashboard/PoliciesComponent';
import {ReportingComponent} from './dashboard/ReportingComponent';

class Dashboard extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <div id="mainContainer" className="container-fluid">
        <div id="menuSidebar" className="col-md-2">
          <MenuItems />
        </div>
        <div className="topNav"></div>
        <div className="mainPanel">{this.props.children}</div>
      </div>
    );
  }
}
export default Dashboard;

0 个答案:

没有答案