dvajs/dva-knowledgemap

动态路由 与 去除url _k 参数貌似有冲突

pengfeiWang opened this issue · 0 comments

版本

"dva": "^1.2.1",
"history": "^4.6.1",
"react": "^15.4.0",

入口 index.js

import dva from 'dva';
import { createHashHistory } from 'history';
import { browserHistory, hashHistory, useRouterHistory } from 'dva/router';
import createLoading from 'dva-loading';
const app = dva({
  ...createLoading(),
  history: useRouterHistory(createHashHistory)({ queryKey: false }),
  onError (error) {
    console.error('app onError -- ', error);
  }
});

// 2. Plugins
// app.use({});

// 3. Model
app.model(require('./models/app'));

// app.model(require("./models/main"));

// 4. Router
app.router(require('./router'));

// 5. Start
app.start('#root');

路由 router.js

import React, { PropTypes } from 'react';
import { Router, Route, browserHistory } from 'dva/router';
import App from './routes/app/';

function Routers ({ history, app }) {
  const routes = [{
    path: '/',
    component: App,
    getIndexRoute (nextState, cb) {
      require.ensure([], require => {
        cb(null, { components: require('./routes/main/') });
      }, 'main');
    },
    childRoutes: [
      {
        path: '/console',
        getComponent (nextState, cb) {
          require.ensure([], require => {
            cb(null, require('./routes/console/'));
          }, 'console');
        }
      },
      {
        path: '*',
        getComponent (nextState, cb) {
          require.ensure([], require => {
            cb(null, require('./routes/error/'));
          }, 'error');
        }
      }
    ]
  }];
  return (<Router history={history} routes={routes} />);
}

Routers.propTypes = {
  history: PropTypes.object,
  app: PropTypes.object
};
export default Routers;