From 87ca9fd5ab53a9d46203c750bd2f990a589520bb Mon Sep 17 00:00:00 2001 From: jim Date: Wed, 17 Jan 2018 15:36:54 +0800 Subject: [PATCH] fix #729 prevent pollution url history --- src/layouts/BasicLayout.js | 11 ++++++++--- src/models/login.js | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 0f5e826e..59b254cf 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -102,10 +102,15 @@ class BasicLayout extends React.PureComponent { // According to the url parameter to redirect // 这里是重定向的,重定向到 url 的 redirect 参数所示地址 const urlParams = new URL(window.location.href); - const redirect = urlParams.searchParams.get('redirect') || '/dashboard/analysis'; + + const redirect = urlParams.searchParams.get('redirect'); // Remove the parameters in the url - urlParams.searchParams.delete('redirect'); - window.history.pushState(null, 'redirect', urlParams.href); + if (redirect) { + urlParams.searchParams.delete('redirect'); + window.history.replaceState(null, 'redirect', urlParams.href); + } else { + return '/dashboard/analysis'; + } return redirect; } handleMenuCollapse = (collapsed) => { diff --git a/src/models/login.js b/src/models/login.js index 044b264d..5efd5f19 100644 --- a/src/models/login.js +++ b/src/models/login.js @@ -31,7 +31,7 @@ export default { const pathname = yield select(state => state.routing.location.pathname); // add the parameters in the url urlParams.searchParams.set('redirect', pathname); - window.history.pushState(null, 'login', urlParams.href); + window.history.replaceState(null, 'login', urlParams.href); } finally { // yield put(routerRedux.push('/user/login')); // Login out after permission changes to admin or user -- GitLab