Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React redux找不到存储_Reactjs_Express_Redux_React Router_React Redux - Fatal编程技术网

Reactjs React redux找不到存储

Reactjs React redux找不到存储,reactjs,express,redux,react-router,react-redux,Reactjs,Express,Redux,React Router,React Redux,我正在使用React+Redux+Express。每当我重新加载我的localhost/courses时,我都会遇到一个错误:找不到“store”。但是如果我从localhost->click转到nav-course,一切都正常。我怎样才能解决这个问题 错误 不变冲突:在上下文或上下文中找不到“存储” “连接(课程)”的道具。将根组件包装在 提供者,或将“存储”作为道具显式传递给“连接(课程)” store.js const middleware = applyMiddleware(promis

我正在使用React+Redux+Express。每当我重新加载我的
localhost/courses
时,我都会遇到一个错误:找不到“store”。但是如果我从
localhost->click转到nav-course
,一切都正常。我怎样才能解决这个问题

错误

不变冲突:在上下文或上下文中找不到“存储” “连接(课程)”的道具。将根组件包装在 提供者,或将“存储”作为道具显式传递给“连接(课程)”

store.js

const middleware = applyMiddleware(promise(), thunk, logger());

export default createStore(reducer, middleware);
window.onload = () => {
  ReactDOM.render(
    <Provider store={store}>
      <Router history={browserHistory} routes={routes} onUpdate={() => window.scrollTo(0, 0)}/>
    </Provider>
    , document.getElementById('main'));
};
const routes = (
  <Route path='/' component={Layout}>
    <IndexRoute component={Home}/>
    <Route path='courses' data={data} component={Course}>          
  </Route>
);

export default routes;
class Course extends React.Component {
  static contextTypes = {
    router: React.PropTypes.object,
  };

  componentWillMount() {
    this.props.dispatch(fetchVocabulary());
  };

  render() {
    console.log(this.props.words);
    return (
      <div>
        ...
      </div>
    );
  };
}

export default connect((store) => {
  return {
    words: store.vocabulary.words
  };
})(Course);
App.js

const middleware = applyMiddleware(promise(), thunk, logger());

export default createStore(reducer, middleware);
window.onload = () => {
  ReactDOM.render(
    <Provider store={store}>
      <Router history={browserHistory} routes={routes} onUpdate={() => window.scrollTo(0, 0)}/>
    </Provider>
    , document.getElementById('main'));
};
const routes = (
  <Route path='/' component={Layout}>
    <IndexRoute component={Home}/>
    <Route path='courses' data={data} component={Course}>          
  </Route>
);

export default routes;
class Course extends React.Component {
  static contextTypes = {
    router: React.PropTypes.object,
  };

  componentWillMount() {
    this.props.dispatch(fetchVocabulary());
  };

  render() {
    console.log(this.props.words);
    return (
      <div>
        ...
      </div>
    );
  };
}

export default connect((store) => {
  return {
    words: store.vocabulary.words
  };
})(Course);

由于您使用的是
browserHistory
,因此需要使用
historyApiFallback

devServer: {
        historyApiFallback:true
    }

这将使用
connect history api fallback
提供
index.html
如果路由与任何其他文件不匹配,那么所有路由都将与此文件相关

Hi,是否可以仅第一次连接到存储?我注意到,每次单击导航/课程时,我的api都会做出响应。恐怕我以前没有试过,我也没有答案。还有一个问题:当我转到本地主机/课程时,一个页面首先返回404,然后返回正常。我检查了我的控制台网络,状态是404。你遇到过这个问题吗?