diff --git a/src/layouts/UserLayout.js b/src/layouts/UserLayout.js index 188ba102fb69cf83c5838df8946558f36a2f2437..93ca4dc57ce07d84d6ca80c1df5417685e7be556 100644 --- a/src/layouts/UserLayout.js +++ b/src/layouts/UserLayout.js @@ -5,7 +5,7 @@ import { Icon } from 'antd'; import GlobalFooter from '../components/GlobalFooter'; import styles from './UserLayout.less'; import logo from '../assets/logo.svg'; -import { getRoutes } from '../utils/utils'; +import { getRoutes, getPageQuery } from '../utils/utils'; const links = [ { @@ -33,8 +33,8 @@ const copyright = ( function getLoginPathWithRedirectPath() { const routePath = '/user/login'; - const urlParams = new URL(window.location.href); - const redirect = urlParams.searchParams.get('redirect'); + const params = getPageQuery(); + const { redirect } = params; if (redirect) { return `${routePath}?redirect=${encodeURIComponent(redirect)}`; } diff --git a/src/models/login.js b/src/models/login.js index d01b2c27cb294e36cfe285a951420fa88d8e88ba..14bdd76cd256816de0fad8208b4ad0f4d04ac215 100644 --- a/src/models/login.js +++ b/src/models/login.js @@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router'; import { fakeAccountLogin } from '../services/api'; import { setAuthority } from '../utils/authority'; import { reloadAuthorized } from '../utils/Authorized'; +import { getPageQuery } from '../utils/utils'; export default { namespace: 'login', @@ -21,11 +22,15 @@ export default { if (response.status === 'ok') { reloadAuthorized(); const urlParams = new URL(window.location.href); - let redirect = urlParams.searchParams.get('redirect'); + const params = getPageQuery(); + let { redirect } = params; if (redirect) { const redirectUrlParams = new URL(redirect); if (redirectUrlParams.origin === urlParams.origin) { redirect = redirect.substr(urlParams.origin.length); + if (redirect.startsWith('/#')) { + redirect = redirect.substr(2); + } } else { window.location.href = redirect; return; diff --git a/src/utils/utils.js b/src/utils/utils.js index 68618150c81565f60d56c1df2b7c736956be67d1..ab4acb179e3f2497786c9200ac829f86017ae1a8 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,4 +1,5 @@ import moment from 'moment'; +import { parse } from 'qs'; export function fixedZero(val) { return val * 1 < 10 ? `0${val}` : val; @@ -161,6 +162,10 @@ export function getRoutes(path, routerData) { return renderRoutes; } +export function getPageQuery() { + return parse(window.location.href.split('?')[1]); +} + /* eslint no-useless-escape:0 */ const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;