react-route显示空白页面

时间:2016-12-07 10:06:46

标签: reactjs routes react-router

我的问题是react-route显示空白页面,控制台或webpack中没有错误显示。我尝试删除所有路由器并替换为App,但它显示空白页面。

这是我的main.js文件。



import React from 'react'
import ReactDOM from 'react-dom'
import {Provider} from 'react-redux'
import {createStore, combineReducers} from 'redux'
import { Router, Route, browserHistory, IndexRoute } from 'react-router'

import Index from './containers/Index.js'
import App from './containers/App.js'
import pollReducer from './reducers/pollReducer.js'

var reducers = combineReducers({
  poll: pollReducer
})

var store = createStore(reducers);

ReactDOM.render(
  <Provider store={store}>
    <Router>
      <Route path="/" component={Index} />
      <Route path="/question" component={App} />
    </Router>
  </Provider>
, document.getElementById('app'))
&#13;
&#13;
&#13;

这是我的App和Index js文件

&#13;
&#13;
import React from 'react'

class App extends React.Component {
  render(){
    return(
      <div>
        This is App page
      </div>
    )
  }
}

export default App
&#13;
&#13;
&#13;

这是我的Index.js文件

&#13;
&#13;
import React from 'react'

class Index extends React.Component {
  render(){
    return(
      <div>
        This is asdasdasda
      </div>
    )
  }
}

export default Index
&#13;
&#13;
&#13;

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

因为您忘记定义history,请使用此选项:

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