Erroron reactredux路由器

时间:2016-09-03 10:23:09

标签: reactjs redux redux-router

我使用此代码创建路由redux路由器

import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import { Router, Route, browserHistory } from 'react-router'
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
import Calendar from '../calendar/calendar'
import Cards from '../cards/cards'

const history = syncHistoryWithStore(browserHistory)
const App= () => {
return <div>
    <h2>start</h2>
    <a href="/calendar">calendar</a>
    <a href="/cards">cards</a>
</div>
}

const store = createStore(
 combineReducers({
   routing: routerReducer
 })
)


ReactDOM.render(
<Provider store={store}>
{ /* Tell the Router to use our enhanced history */ }
<Router history={history}>
  <Route path="/" component={App}>
    <Route path="calendar" component={Calendar}/>
    <Route path="cards" component={Cards}/>
  </Route>
</Router>
</Provider>,
document.getElementById('mount')
)

我收到此错误

  

&#34;未捕获的TypeError:无法读取属性&#39; getState&#39;未定义&#34;

我试图在app redux上实现路由器redux 感谢

卡洛斯·维埃拉

1 个答案:

答案 0 :(得分:0)

从您提供的代码中很难确切地知道您的问题是什么,但是如果您尝试使用React-Router,您可能希望首先更改链接以反映其使用。

尝试更换:

<a href="/calendar">calendar</a>
<a href="/cards">cards</a>

有了这个:

<Link to="/calendar">calender</Link>
<Link to="/cards">cards</Link>

将React-Router中的链接放在文件的顶部:

import { Router, Route, browserHistory, Link } from 'react-router'

如果这不能解决您的问题,并且您发布了尝试初始化state的位置,也可能尝试setState,那么您可能会收到有关该错误的更多帮助。