简体   繁体   English

警告:道具类型失败:提供给“路线”的道具属性无效。 &警告:[反应路由器]位置“ /”与任何路线均不匹配

[英]Warning: Failed prop type: Invalid prop `component` supplied to `Route`. & Warning: [react-router] Location “/” did not match any routes

I speak little engilsh,sorry first. 我会说一点小礼,抱歉。

I have searched some similar questions, but not help. 我搜索了一些类似的问题,但没有帮助。 Can't figure out what happen by myself, it almost spend me 1 hours. 我不知道自己会发生什么,几乎花了我一个小时。

I start my project with latest yeoman & generator-react-webpack. 我从最新的yeoman和generator-react-webpack开始我的项目。

Some error always exist.In the browser console. 在浏览器控制台中总是存在一些错误。

Warning: Failed prop type: Invalid prop `children` supplied to`Router`.
Warning: [react-router] Location "/" did not match any routes

here is index.js . 这是index.js

import 'core-js/fn/object/assign';
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, hashHistory, IndexRoute} from 'react-router';

import IndexPage from './components/IndexPage';
import Pages from './components/Pages';

ReactDOM.render((
    <Router history={hashHistory}>
        <Route path="/" component={IndexPage} />
        <Route path="/pages" component={Pages} />
    </Router>
), document.getElementById('webapp'));

here is Indexpage.js . 这是Indexpage.js

import React, {Component} from 'react';
export default class IndexPage extends Component {
    render() {
        return (
            <div>1234</div>
        )
    }
}

and here is pages.js . 这是pages.js

import React, {Component} from 'react';
export default class Pages extends Component {
    render() {
        return (
            <div>9876</div>
        )
    }
}

Checkout if the filenames and import statements have the correct spelling. 检查文件名和导入语句的拼写是否正确。

pages.js should be P ages.js pages.js应该是P ages.js
Indexpage.js should be Index P age.js Indexpage.js应为Index P age.js

Or change it in the import statements.. its case-sensitive. 或在import语句中更改它。区分大小写。

The docs says you have to wrap your Routes with a main Router / 文档说您必须使用主路由器/来包装路由

  <Router history={browserHistory}>
    <Route path="/" component={App}>

      <Route path="about" component={About}/>
      <Route path="users" component={Users}>
        <Route path="/user/:userId" component={User}/>
      </Route>
      <Route path="*" component={NoMatch}/>

    </Route>
  </Router>

  // this is the main App component
  const App = ({children}) => (
     <div id="main-layout">{children}</div>
  )

Your pages.js has a wrong class name. 您的pages.js的类名错误。 Instead of also calling it as IndexPage, you want to call it as Pages like below. 与其将其称为IndexPage,还不如将其称为Pages,如下所示。

import React, {Component} from 'react';
export default class Pages extends Component {
    render() {
        return (
            <div>9876</div>
        )
    }
}

暂无
暂无

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

相关问题 反应路由器,多个组件警告:道具类型失败:提供给“路线”的道具“组件”无效 - 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 组件 - Warning: Failed prop type: Invalid prop 'component' supplied to 'Route': the prop is not a valid React component in Route 警告:道具类型失败:提供给“路线”的道具属性无效。 在途中 - Warning: Failed prop type: Invalid prop `component` supplied to `Route`. in Route React-Router:失败的prop类型:在route中提供给Route的无效prop`component` - React-Router: Failed prop type: Invalid prop `component` supplied to `Route` in route 警告:失败的道具类型:提供给“路由”的“对象”类型的无效道具“组件”,预期的“函数”使用 react-router-dom 错误 - Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function` Error using react-router-dom 反应警告:失败的道具类型:提供的“对象”类型的无效道具 - React Warning: Failed prop type: Invalid prop of type `Object` supplied 警告:道具类型失败:提供给“Route”的“object”类型的无效道具“component”,预期为“function” - Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function` 警告:道具类型失败:提供给“路线”的道具“组件”无效 - Warning: Failed propType: Invalid prop 'component' supplied to 'route' 警告:失败的 propType:提供给 `Route` 的 prop`component` 无效 - Warning: Failed propType: Invalid prop `component` supplied to `Route`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM