【问题标题】:React Router Error: Invalid prop `component` supplied to `Route`反应路由器错误:提供给“路由”的无效道具“组件”
【发布时间】:2016-08-19 16:11:53
【问题描述】:

当我在浏览器上运行我的应用程序时,我的控制台中出现以下错误。

警告:道具类型失败:提供给“路线”的道具“组件”无效。

我目前正在使用以下开发需求的版本

react v0.14.8 react-router v2.3.0 Webpack v1.13.0 babel-loader v6.2.4 babel-core v6.7.7 babel-preset-es2015 v6.6.0 babel-polyfill v6.7.4 babel-preset-react v6.5.0 babel-register v6.7.2 babel-runtime v6.6.1

这就是我的路由文件的样子。

import {Route, IndexRoute} from '../node_modules/react-router';
import App from '../components/app';
import Dashboard from '../components/dashboard';
import UsersList from '../components/users/list';
import CoursesList from '../components/courses/list';

// Define routes

const routes = (
    <Route path='/' component={App}>
         <IndexRoute component={Dashboard}/>
         <Route path='/dashboard' component={Dashboard} />
         <Route path='/users' component={UsersList} />
         <Route path='/courses' component={CoursesList} />
    </Route>
);

export default routes;

这是我的主要 js 的样子

import React from './node_modules/react';
import ReactDOM from './node_modules/react-dom';
import {Router, browserHistory} from './node_modules/react-router';
import routes from './configs/routes';
// Render
ReactDOM.render(<Router history={browserHistory} routes={routes} />, document.getElementById("app") );

请问这个错误是从哪里来的,我该如何解决?

【问题讨论】:

    标签: reactjs react-router


    【解决方案1】:

    你必须像这样设置你的路由器

    <Router history={browserHistory} >{routes}</Router>
    

    而不是

    <Router history={browserHistory} routes={routes} />
    

    【讨论】:

    • 我的天啊,我按你说的更新了我的主js,发现我没有导出App组件,你刚刚救了我,谢谢,
    猜你喜欢
    • 2016-06-11
    • 1970-01-01
    • 2015-09-01
    • 2019-08-15
    • 2016-10-23
    • 2017-03-11
    • 2019-05-17
    • 1970-01-01
    • 2020-03-26
    相关资源
    最近更新 更多