【问题标题】:Erroron reactredux router反应redux路由器上的错误
【发布时间】:2016-09-03 10:23:09
【问题描述】:

我正在使用此代码来创建路由 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')
)

我收到了这个错误

“未捕获的类型错误:无法读取未定义的属性 'getState'”

我正在尝试在 app redux 上实现路由器 redux 谢谢

卡洛斯·维埃拉

【问题讨论】:

  • 我正在关注这个链接github.com/reactjs/redux
  • 你必须在你调用getState的地方显示代码
  • 我把状态放在哪里?我只是按照github.com/reactjs/react-router-redux下链接的代码行
  • 你能告诉我们你创建商店的代码吗?
  • 我正在关注上面的网站,并使用 const store = createStore( combineReducers({ routing: routerReducer }) ) 创建商店

标签: reactjs redux redux-router


【解决方案1】:

从您提供的代码中很难准确判断您的问题是什么,但是如果您尝试使用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 的位置发布,您可能会收到更多有关该错误的帮助。

【讨论】:

  • 您好,感谢您的回答,老实说,我并没有初始化一个状态,我只是按照上面的 react redux 路由器的网站并实现代码......它应该可以工作,但我没有知道发生了什么。我会尝试你的改变......我会给出反馈。谢谢卡洛斯·维埃拉
猜你喜欢
  • 2018-01-14
  • 2021-03-01
  • 2016-03-07
  • 1970-01-01
  • 2016-01-04
  • 1970-01-01
  • 2016-08-24
  • 2020-08-24
相关资源
最近更新 更多