Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pengfeiWang opened this issue Apr 11, 2017 · 0 comments
Open

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

pengfeiWang opened this issue Apr 11, 2017 · 0 comments

Comments

@pengfeiWang
Copy link

pengfeiWang commented Apr 11, 2017

版本

"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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant