Commit 63c8ceb2 authored by yoyo837's avatar yoyo837 Committed by 陈帅

兼容hash 路由模式

parent f904467d
...@@ -5,7 +5,7 @@ import { Icon } from 'antd'; ...@@ -5,7 +5,7 @@ import { Icon } from 'antd';
import GlobalFooter from '../components/GlobalFooter'; import GlobalFooter from '../components/GlobalFooter';
import styles from './UserLayout.less'; import styles from './UserLayout.less';
import logo from '../assets/logo.svg'; import logo from '../assets/logo.svg';
import { getRoutes } from '../utils/utils'; import { getRoutes, getPageQuery } from '../utils/utils';
const links = [ const links = [
{ {
...@@ -33,8 +33,8 @@ const copyright = ( ...@@ -33,8 +33,8 @@ const copyright = (
function getLoginPathWithRedirectPath() { function getLoginPathWithRedirectPath() {
const routePath = '/user/login'; const routePath = '/user/login';
const urlParams = new URL(window.location.href); const params = getPageQuery();
const redirect = urlParams.searchParams.get('redirect'); const { redirect } = params;
if (redirect) { if (redirect) {
return `${routePath}?redirect=${encodeURIComponent(redirect)}`; return `${routePath}?redirect=${encodeURIComponent(redirect)}`;
} }
......
...@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router'; ...@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router';
import { fakeAccountLogin } from '../services/api'; import { fakeAccountLogin } from '../services/api';
import { setAuthority } from '../utils/authority'; import { setAuthority } from '../utils/authority';
import { reloadAuthorized } from '../utils/Authorized'; import { reloadAuthorized } from '../utils/Authorized';
import { getPageQuery } from '../utils/utils';
export default { export default {
namespace: 'login', namespace: 'login',
...@@ -21,11 +22,15 @@ export default { ...@@ -21,11 +22,15 @@ export default {
if (response.status === 'ok') { if (response.status === 'ok') {
reloadAuthorized(); reloadAuthorized();
const urlParams = new URL(window.location.href); const urlParams = new URL(window.location.href);
let redirect = urlParams.searchParams.get('redirect'); const params = getPageQuery();
let { redirect } = params;
if (redirect) { if (redirect) {
const redirectUrlParams = new URL(redirect); const redirectUrlParams = new URL(redirect);
if (redirectUrlParams.origin === urlParams.origin) { if (redirectUrlParams.origin === urlParams.origin) {
redirect = redirect.substr(urlParams.origin.length); redirect = redirect.substr(urlParams.origin.length);
if (redirect.startsWith('/#')) {
redirect = redirect.substr(2);
}
} else { } else {
window.location.href = redirect; window.location.href = redirect;
return; return;
......
import moment from 'moment'; import moment from 'moment';
import { parse } from 'qs';
export function fixedZero(val) { export function fixedZero(val) {
return val * 1 < 10 ? `0${val}` : val; return val * 1 < 10 ? `0${val}` : val;
...@@ -161,6 +162,10 @@ export function getRoutes(path, routerData) { ...@@ -161,6 +162,10 @@ export function getRoutes(path, routerData) {
return renderRoutes; return renderRoutes;
} }
export function getPageQuery() {
return parse(window.location.href.split('?')[1]);
}
/* eslint no-useless-escape:0 */ /* eslint no-useless-escape:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment