react Cannot GET /

来源:互联网 发布:移动网络代理成电信的 编辑:程序博客网 时间:2024/06/08 09:03

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

import dva, { connect } from 'dva';import { Router, Route } from 'dva/router';import React from 'react';import styles from './index.less';import key from 'keymaster';const app = dva();app.model({  namespace: 'count',  state: {    record: 0,    current: 0,  },  reducers: {    add(state) {      const newCurrent = state.current + 1;      return { ...state,        record: newCurrent > state.record ? newCurrent : state.record,        current: newCurrent,      };    },    minus(state) {      return { ...state, current: state.current - 1};    },  },  effects: {    *add(action, { call, put }) {      yield call(delay, 1000);      yield put({ type: 'minus' });    },  },  subscriptions: {    keyboardWatcher({ dispatch }) {      key('⌘+up, ctrl+up', () => { dispatch({type:'add'}) });    },  },});const CountApp = ({count, dispatch}) => {  return (    <div className={styles.normal}>      <div className={styles.record}>Highest Record: {count.record}</div>      <div className={styles.current}>{count.current}</div>      <div className={styles.button}>        <button onClick={() => { dispatch({type: 'count/add'}); }}>+</button>      </div>    </div>  );};// Helpersfunction delay(timeout){  return new Promise(resolve => {    setTimeout(resolve, timeout);  });}function mapStateToProps(state) {  return { count: state.count };}const HomePage = connect(mapStateToProps)(CountApp);// const HomePage = () => <div>Hello Dva.</div>;app.router(({history}) =>  <Router history={history}>    <Route path="/" component={HomePage} />  </Router>);// ---------app.start('#root');

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

import dva, { connect } from 'dva';import { Router, Route } from 'dva/router';import React from 'react';import styles from './index.less';import key from 'keymaster';import './index.html';const app = dva();app.model({  namespace: 'count',  state: {    record: 0,    current: 0,  },  reducers: {    add(state) {      const newCurrent = state.current + 1;      return { ...state,        record: newCurrent > state.record ? newCurrent : state.record,        current: newCurrent,      };    },    minus(state) {      return { ...state, current: state.current - 1};    },  },  effects: {    *add(action, { call, put }) {      yield call(delay, 1000);      yield put({ type: 'minus' });    },  },  subscriptions: {    keyboardWatcher({ dispatch }) {      key('⌘+up, ctrl+up', () => { dispatch({type:'add'}) });    },  },});const CountApp = ({count, dispatch}) => {  return (    <div className={styles.normal}>      <div className={styles.record}>Highest Record: {count.record}</div>      <div className={styles.current}>{count.current}</div>      <div className={styles.button}>        <button onClick={() => { dispatch({type: 'count/add'}); }}>+</button>      </div>    </div>  );};// Helpersfunction delay(timeout){  return new Promise(resolve => {    setTimeout(resolve, timeout);  });}function mapStateToProps(state) {  return { count: state.count };}const HomePage = connect(mapStateToProps)(CountApp);// const HomePage = () => <div>Hello Dva.</div>;app.router(({history}) =>  <Router history={history}>    <Route path="/" component={HomePage} />  </Router>);// ---------app.start('#root');