react Cannot GET /

前端之家收集整理的这篇文章主要介绍了react Cannot GET /前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如果是路由都配置好了,也没有报其他的编译错误,如下:

  1. import dva,{ connect } from 'dva';
  2. import { Router,Route } from 'dva/router';
  3. import React from 'react';
  4. import styles from './index.less';
  5. import key from 'keymaster';
  6.  
  7. const app = dva();
  8.  
  9. app.model({
  10. namespace: 'count',state: {
  11. record: 0,current: 0,},reducers: {
  12. add(state) {
  13. const newCurrent = state.current + 1;
  14. return { ...state,record: newCurrent > state.record ? newCurrent : state.record,current: newCurrent,};
  15. },minus(state) {
  16. return { ...state,current: state.current - 1};
  17. },effects: {
  18. *add(action,{ call,put }) {
  19. yield call(delay,1000);
  20. yield put({ type: 'minus' });
  21. },subscriptions: {
  22. keyboardWatcher({ dispatch }) {
  23. key('⌘+up,ctrl+up',() => { dispatch({type:'add'}) }); },}); const CountApp = ({count,dispatch}) => {
  24. return (
  25. <div className={styles.normal}>
  26. <div className={styles.record}>Highest Record: {count.record}</div>
  27. <div className={styles.current}>{count.current}</div>
  28. <div className={styles.button}>
  29. <button onClick={() => { dispatch({type: 'count/add'}); }}>+</button>
  30. </div>
  31. </div>
  32. );
  33. };
  34.  
  35.  
  36. // Helpers
  37.  
  38. function delay(timeout){
  39. return new Promise(resolve => {
  40. setTimeout(resolve,timeout);
  41. });
  42. }
  43.  
  44. function mapStateToProps(state) {
  45. return { count: state.count };
  46. }
  47. const HomePage = connect(mapStateToProps)(CountApp);
  48. // const HomePage = () => <div>Hello Dva.</div>;
  49.  
  50.  
  51.  
  52. app.router(({history}) => <Router history={history}> <Route path="/" component={HomePage} /> </Router> ); // --------- app.start('#root');

那就说明你没有把 index.html 文件引入进来,加上 import ‘./index.html’; 这句话就好了

  1. import dva,Route } from 'dva/router';
  2. import React from 'react';
  3. import styles from './index.less';
  4. import key from 'keymaster';
  5. import './index.html';
  6.  
  7. const app = dva();
  8.  
  9. app.model({
  10. namespace: 'count',timeout);
  11. });
  12. }
  13.  
  14. function mapStateToProps(state) {
  15. return { count: state.count };
  16. }
  17. const HomePage = connect(mapStateToProps)(CountApp);
  18. // const HomePage = () => <div>Hello Dva.</div>;
  19.  
  20.  
  21.  
  22. app.router(({history}) => <Router history={history}> <Route path="/" component={HomePage} /> </Router> ); // --------- app.start('#root');

猜你在找的React相关文章