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

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

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