Skip to content

Commit

Permalink
example(user-dashboard): migrate to dva@2
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Sep 1, 2017
1 parent 52b6efa commit eef1bcf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/dva-example-react-router-3/package.json
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"babel-runtime": "^6.9.2",
"dva-react-router-3": "^0.1.2",
"dva-react-router-3": "^0.2.0",
"react": "^15.4.0",
"react-dom": "^15.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dva-example-user-dashboard/.roadhogrc
Expand Up @@ -28,7 +28,7 @@
]
}
},
"dllPlugin": {
"xdllPlugin": {
"exclude": [
"babel-runtime"
],
Expand Down
5 changes: 3 additions & 2 deletions packages/dva-example-user-dashboard/package.json
Expand Up @@ -12,8 +12,9 @@
"dependencies": {
"antd": "^2.6.4",
"babel-runtime": "^6.22.0",
"dva": "^1.2.0",
"dva": "^2.0.0-0",

This comment has been minimized.

Copy link
@dkvirus

dkvirus Oct 9, 2017

2.0.0-0 啥意思,是笔误还是另有玄机~~

This comment has been minimized.

Copy link
@joriewong

joriewong Dec 28, 2017

上个版本号 "dva": "^1.4.0-beta.1"

"dva-loading": "^0.2.0",
"query-string": "^5.0.0",
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
Expand All @@ -30,6 +31,6 @@
"expect": "^1.20.2",
"husky": "^0.13.0",
"redbox-react": "^1.3.2",
"roadhog": "^0.6.0"
"roadhog": "^1.2.0-beta.1"
}
}
4 changes: 3 additions & 1 deletion packages/dva-example-user-dashboard/src/models/users.js
@@ -1,3 +1,4 @@
import queryString from 'query-string';
import * as usersService from '../services/users';

export default {
Expand Down Expand Up @@ -43,7 +44,8 @@ export default {
},
subscriptions: {
setup({ dispatch, history }) {
return history.listen(({ pathname, query }) => {
return history.listen(({ pathname, search }) => {
const query = queryString.parse(search);
if (pathname === '/users') {
dispatch({ type: 'fetch', payload: query });
}
Expand Down
53 changes: 22 additions & 31 deletions packages/dva-example-user-dashboard/src/router.js
@@ -1,38 +1,29 @@
import React from 'react';
import { Router } from 'dva/router';

const cached = {};
function registerModel(app, model) {
if (!cached[model.namespace]) {
app.model(model);
cached[model.namespace] = 1;
}
}
import { Router, Switch, Route } from 'dva/router';
import dynamic from 'dva/dynamic';

function RouterConfig({ history, app }) {
const routes = [
{
path: '/',
name: 'IndexPage',
getComponent(nextState, cb) {
require.ensure([], (require) => {
cb(null, require('./routes/IndexPage'));
});
},
},
{
path: '/users',
name: 'UsersPage',
getComponent(nextState, cb) {
require.ensure([], (require) => {
registerModel(app, require('./models/users'));
cb(null, require('./routes/Users'));
});
},
},
];
const IndexPage = dynamic({
app,
component: import('./routes/IndexPage'),
});

const Users = dynamic({
app,
models: [
import('./models/users'),
],
component: import('./routes/Users'),
});

return <Router history={history} routes={routes} />;
return (
<Router history={history}>
<Switch>
<Route exact path="/" component={IndexPage} />
<Route exact path="/users" component={Users} />
</Switch>
</Router>
);
}

export default RouterConfig;

2 comments on commit eef1bcf

@joriewong
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

browser.js?87e2:40Uncaught Error: You have provided a history object created with history v4.x or v2.x and earlier. This version of React Router is only compatible with v3 history objects. Please change to history v3.x.

@joriewong
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dependencies": {
    "antd": "^2.6.4",
    "babel-runtime": "^6.22.0",
    "dva": "^2.0.0-0",
    "dva-loading": "^0.2.0",
    "query-string": "^5.0.0",
    "react": "^16.1.1",
    "react-dom": "^16.1.1"
  }

Please sign in to comment.