提交 a4b62d05 authored 作者: vipcxj's avatar vipcxj

update from react-router-v3 to react-router-v4

上级 a7821093
...@@ -15,11 +15,9 @@ const resource_proxy = { ...@@ -15,11 +15,9 @@ const resource_proxy = {
}; };
module.exports = { module.exports = {
alias: {
"dva": "dva-react-router-3"
},
entry: "src/index.js", entry: "src/index.js",
html: { html: {
title: 'base project',
template: "src/index.ejs", template: "src/index.ejs",
}, },
theme: { theme: {
......
...@@ -16,18 +16,21 @@ ...@@ -16,18 +16,21 @@
"antd": "^3.3.0", "antd": "^3.3.0",
"axo": "0.0.2", "axo": "0.0.2",
"bowser": "^1.8.1", "bowser": "^1.8.1",
"dva": "^2.2.0-beta.2", "dva": "^2.1.0",
"dva-react-router-3": "^1.0.2",
"dva-loading": "^1.0.4", "dva-loading": "^1.0.4",
"fastjson_ref_resolver": "latest", "fastjson_ref_resolver": "latest",
"fingerprintjs": "^0.5.3", "fingerprintjs": "^0.5.3",
"history": "latest",
"is-promise": "^2.1.0",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"lowdb": "^1.0.0", "lowdb": "^1.0.0",
"moment": "^2.18.1", "moment": "^2.18.1",
"prop-types": "^15.6.1", "prop-types": "^15.6.1",
"react": "^16.2.0", "react": "^16.2.0",
"react-async-wrapper": "^0.0.7",
"react-dom": "^16.2.0", "react-dom": "^16.2.0",
"react-json-view": "^1.11.4", "react-json-view": "^1.11.4",
"react-router-4-compat": "^0.1.2",
"resolve-pathname": "^2.1.0", "resolve-pathname": "^2.1.0",
"uuid": "^3.1.0", "uuid": "^3.1.0",
"word-wrap": "^1.2.3", "word-wrap": "^1.2.3",
...@@ -39,6 +42,7 @@ ...@@ -39,6 +42,7 @@
"@storybook/addon-info": "^3.3.15", "@storybook/addon-info": "^3.3.15",
"@storybook/react": "^3.3.15", "@storybook/react": "^3.3.15",
"babel-core": "^7.0.0-bridge.0", "babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^8.2.2",
"babel-plugin-dva-hmr": "^0.4.1", "babel-plugin-dva-hmr": "^0.4.1",
"babel-plugin-import": "^1.6.5", "babel-plugin-import": "^1.6.5",
"babel-plugin-lodash": "^3.3.2", "babel-plugin-lodash": "^3.3.2",
...@@ -47,7 +51,9 @@ ...@@ -47,7 +51,9 @@
"cross-env": "^5.1.3", "cross-env": "^5.1.3",
"ejs-loader": "^0.3.1", "ejs-loader": "^0.3.1",
"enzyme": "^3.3.0", "enzyme": "^3.3.0",
"jest": "^22.4.2",
"eslint-config-airbnb": "^16.1.0", "eslint-config-airbnb": "^16.1.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-lodash-fp": "^2.1.3", "eslint-plugin-lodash-fp": "^2.1.3",
"http-proxy-middleware": "^0.17.4", "http-proxy-middleware": "^0.17.4",
"jsdom": "^11.0.0", "jsdom": "^11.0.0",
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dva Demo</title> <title><%= htmlWebpackPlugin.options.title %></title>
<script src="https://cdn.bootcss.com/babel-polyfill/7.0.0-beta.3/polyfill.min.js"></script> <script src="https://cdn.bootcss.com/babel-polyfill/7.0.0-beta.3/polyfill.min.js"></script>
<!--<link rel="stylesheet" href="/index.css" />--> <!--<link rel="stylesheet" href="/index.css" />-->
</head> </head>
......
import dva from 'dva'; import dva from 'dva';
import createLoading from 'dva-loading'; import createLoading from 'dva-loading';
import moment from 'moment'; import moment from 'moment';
import { history } from './services/route'; import { getHistory } from './services/route';
import { initApp } from './data/app'; import { initApp } from './data/app';
import appModel from './models/app'; import appModel from './models/app';
import routerConfig from './router'; import routerConfig from './router';
...@@ -12,7 +12,7 @@ moment.locale('zh-cn'); ...@@ -12,7 +12,7 @@ moment.locale('zh-cn');
// 1. Initialize // 1. Initialize
const app = dva({ const app = dva({
history, history: getHistory(),
onError(error) { onError(error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
processError(error); processError(error);
......
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Router } from 'dva/router'; import { Router4Compat as Router } from 'react-router-4-compat';
import isString from 'lodash/isString'; import isString from 'lodash/isString';
import get from 'lodash/get'; import get from 'lodash/get';
import config from './utils/config'; import config from './utils/config';
......
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'dva'; import { connect } from 'dva';
import { withRouter } from 'dva/router'; import { withRouter4Compat as withRouter } from 'react-router-4-compat';
import { Layout } from 'antd'; import { Layout } from 'antd';
import SiderLogo from '../../components/layout/sider/SiderLogo'; import SiderLogo from '../../components/layout/sider/SiderLogo';
import SiderMenu from '../../components/layout/sider/SiderMenu'; import SiderMenu from '../../components/layout/sider/SiderMenu';
......
import { connect } from 'dva'; import { connect } from 'dva';
import { withRouter } from 'dva/router'; import { withRouter4Compat as withRouter } from 'react-router-4-compat';
import List from './list'; import List from './list';
import Detail from './detail'; import Detail from './detail';
import route from '../../../../components/hoc/routes'; import route from '../../../../components/hoc/routes';
......
import { browserHistory } from 'dva/router'; import createBrowserHistory from 'history/createBrowserHistory';
import resolvePathname from 'resolve-pathname'; import resolvePathname from 'resolve-pathname';
import isString from 'lodash/isString'; import isString from 'lodash/isString';
import config from '../utils/config'; import config from '../utils/config';
...@@ -31,15 +31,22 @@ const getHistoryBase = (history) => { ...@@ -31,15 +31,22 @@ const getHistoryBase = (history) => {
} }
}; };
export const history = browserHistory; let history;
export const location = {}; let location;
history.listen((loc) => { export const getHistory = (...args) => {
location.pathname = loc.pathname; return history || createHistory(...args);
location.state = loc.state; };
location.search = loc.search; export const getLocation = () => {
location.hash = loc.hash; return location || {};
}); };
export const createHistory = (...args) => {
history = createBrowserHistory(...args);
history.listen((loc) => {
location = { ...loc };
});
return history;
};
export const push = (path, state, withContext = true) => { export const push = (path, state, withContext = true) => {
return history.push(processPath(getHistoryBase(history), path, withContext), state); return history.push(processPath(getHistoryBase(history), path, withContext), state);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论