简体   繁体   English

React Router-组成路线时提供给`Router`的无效道具`children'

[英]React Router - Invalid prop `children` supplied to `Router` when composing routes

Why is it that when I supply the routes within the router all is good but when I compose the routes like below I get a 为什么当我在路由器中提供路由时一切都很好,但是当我编写如下所示的路由时却得到一个

warning.js:36 Warning: Failed prop type: Invalid prop children supplied to Router . in Router (at index.js:62) in Root (at index.js:70) warning.js:36 Warning: Failed prop type: Invalid prop supplied to Router的warning.js:36 Warning: Failed prop type: Invalid propwarning.js:36 Warning: Failed prop type: Invalid prop . in Router (at index.js:62) in Root (at index.js:70) . in Router (at index.js:62) in Root (at index.js:70)

and a 和一个

browser.js:49 Warning: [react-router] Location "/contact" did not match any routes

import React, { PropTypes, Component } from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, Link, IndexRoute, browserHistory } from 'react-router';

class Navigation extends Component {
  render() {
    return (
      <div>
        <ul>
          <li><Link to='/'>Main</Link></li>
          <li><Link to='/about'>About</Link></li>
          <li><Link to='/contact'>Contact</Link></li>
        </ul>
      </div>
    );
  }
};

class Contact extends Component {
  render() {
    return <div>Contact</div>;
  }
}

class About extends Component {
  render() {
    return ( <div>About</div> );
  }
}

class Home extends Component {
  render() {
    return <div>Home</div>;
  }
}

class App extends Component {
  render() {
    return (
      <div>
        <h1>App</h1>
        <Navigation />
        {this.props.children}
      </div>
    );
  }
}


const routes = () => (
  <Route path='/' component={App}>
    <IndexRoute component={Home} />
    <Route path='about' component={About} />
    <Route path='contact' component={Contact} />
  </Route>
)

export default class Root extends Component {
  render() {
    return (
      <Router history={browserHistory}>
        {routes}
      </Router>
    );
  }
}

ReactDOM.render(
  <Root  />,
  document.getElementById('root')
)

I've tried just about all variations. 我已经尝试了几乎所有变体。 Is it possible to compose routes? 是否可以撰写路线? Any help appreciated. 任何帮助表示赞赏。

 export default class Root extends Component { render() { return ( <Router history={browserHistory}> {routes()} </Router> ); } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React.js客户端路由匹配,给出“提供给`Router`的无效道具`routes。” - React.js client route match giving “Invalid prop `routes` supplied to `Router`.” 警告:道具类型失败:提供给“路线”的道具属性无效。 &警告:[反应路由器]位置“ /”与任何路线均不匹配 - Warning: Failed prop type: Invalid prop `component` supplied to `Route`. & Warning: [react-router] Location “/” did not match any routes 反应路由器错误:无效的道具组件提供给路线 - React Router Error: Invalid prop `component` supplied to `Route` 反应路由器,多个组件警告:道具类型失败:提供给“路线”的道具“组件”无效 - react router, multiple components warning: Failed prop type: Invalid prop `component` supplied to `Route` 警告:失败的道具类型:提供给“路由”的无效道具“组件”-react-router-dom - Warning: Failed prop type: Invalid prop 'component' supplied to 'Route' - react-router-dom React-Router:失败的prop类型:在route中提供给Route的无效prop`component` - React-Router: Failed prop type: Invalid prop `component` supplied to `Route` in route 在history.push上使用children prop时,react路由器4未更新 - React router 4 not updating when using children prop on history.push 带有React 16.6 Suspense的React Router“向“ Route”提供了类型为“ object”的无效prop`component`,预期为“ function”。” - React Router with React 16.6 Suspense “Invalid prop `component` of type `object` supplied to `Route`, expected `function`.” 渲染和子道具之间的反应路由器差异 - React router difference between render and children prop 将用户道具传递给所有孩子反应路由器 - pass user prop to all children react router
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM