2016-06-22 45 views
2

當我運行我的瀏覽器的應用程序,我得到我的控制檯上:提供了無效的道具‘組件’:警告:無法propType:無效的道具「組件」供給「路線」

「警告:無法propType到 '路線'」

我的路線文件:

import { Route, IndexRoute } from 'react-router'; 
import React from 'react'; 
import App from './container/App'; 
import PContainer from './container/PContainer/PContainer'; 
import PView from './container/PView/PView'; 

const routes = (
<Route path="/" component={App} > 
    <IndexRoute component={PContainer} /> 
    <Route path="/Posts View" component={PView} /> 
</Route> 
); 

export default routes; 

我PVie w文件:

import React, { Component, PropTypes } from 'react'; 
import { connect } from 'react-redux'; 

class PView extends Component { 

render() { 
    return (
    <div> 
    <h1>List of Posts</h1> 
    </div> 
); 
} 
} 

export default connect()(PView); 

有誰能告訴我爲什麼我得到這個錯誤?

+0

是在路由路徑中允許的空間,如''? – Vikramaditya

+0

是的,它被允許。 –

+1

[Warning:失敗的propType:無效的prop \'component \'提供給\'Route \']可能重複(http://stackoverflow.com/questions/33950433/warning-failed-proptype-in​​valid-prop-component-提供給路由) – James111

回答

1

確保App,PContainer和PView都是有效的React組件。檢查模塊的導入和導出。導出應該帶有「default」,否則應該使用named import:import {somecomp} from './somecomp'。檢查你的路線組件。

你的路線看起來有點奇怪:'./container/PContainer/PContainer''./container/PView/PView'

也許這應該是'./container/PContainer''./container/PView',如果你沒有PContainerPVIEW文件夾。

相關問題