2015-11-05 62 views
1

我有使用react-router的問題。我得到這個錯誤,無法呈現我的應用程序。 enter image description here問題與反應路由器未捕獲的錯誤:不變違規:元素類型無效:預期一個字符串(對於內置組件)

我在尋找答案,但找不到有用的東西。所以如果有人能幫助我,我會非常感激,因爲我被卡住了。

import React from 'react'; 
 
import HomePage from './pages/page.create.jsx'; 
 
import { render } from 'react-dom'; 
 
import { Router, Route, IndexRoute, Link, IndexLink } from 'react-router'; 
 
import { createHistory, useBasename } from 'history'; 
 

 
class CreatePage extends React.Component { 
 
    constructor (props) { 
 
     super(props); 
 
     this.state = {}; 
 
    } 
 

 
    render() { 
 
     return (
 
      <div className='b-container'> 
 
       <div className = 'test'> 
 
        <h1>Hello World!</h1> 
 
       </div> 
 
       {this.props.children} 
 
      </div> 
 
     ); 
 
    } 
 
} 
 

 
//render(<HomePage />, document.body); 
 

 
const routes = { 
 
    path: '/', 
 
    component: CreatePage, 
 
    childRoutes: [ 
 
     { path: 'about', component: HomePage } 
 
    ] 
 
}; 
 

 
render(<Router>{routes}</Router>, document.getElementById('root'));

+0

你的webpack配置是什麼樣的? – 4m1r

+0

https://github.com/IlyaLytvynov/notes_manager/blob/master/webpack.config.js - 這是一個鏈接到webpack配置文件。 –

+0

雅,你的配置看起來不錯。我認爲@topheman釘了它。 – 4m1r

回答

1

您沒有通過歷史到路由器。像這樣的應該做的伎倆:

const history = createHistory(); 
render(<Router history={history}>{routes}</Router>, document.getElementById('root')) 
0

謝謝大家。問題出在反應路由器版本中,我嘗試使用v 1.0中的功能,但安裝的是v13.5。爲了解決我重新安裝路由器,一切都很好。

相關問題