【问题标题】:react-route display blank pagereact-route 显示空白页
【发布时间】:2017-04-22 05:24:39
【问题描述】:

我的问题是 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'))

这是我的应用和索引 js 文件

import React from 'react'

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

export default App

这是我的 Index.js 文件

import React from 'react'

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

export default Index

感谢您的帮助。

【问题讨论】:

  • 你的 index.html 是什么样的?
  • @Alexander 这是一个空白页

标签: reactjs routes react-router


【解决方案1】:

因为你忘了定义history,所以使用这个:

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

【讨论】:

  • 感谢它的工作,但是当我插入此代码 var store = createStore(reducers) 时,它会再次进入空白页
猜你喜欢
  • 1970-01-01
  • 2022-01-23
  • 2022-07-21
  • 2019-01-22
  • 1970-01-01
  • 2018-02-16
  • 1970-01-01
  • 2019-02-06
相关资源
最近更新 更多