From b7cd598ee85ab042a40dea013225ed4abc26a87d Mon Sep 17 00:00:00 2001 From: Yaodong Yu <2814461814@qq.com> Date: Fri, 25 Nov 2022 23:08:45 +0800 Subject: [PATCH] fix: fail to return after flush the page (#1325) * fix: fail to return after flush the page Old methed just get the url path parameter when click the butten. But when the page flushed, the returnUrl will disappear, so can not return to the specified page. * Update UserEditPage.js * Update UserEditPage.js Co-authored-by: hsluoyz --- web/src/UserEditPage.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index b6af1070..95546e98 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -49,6 +49,7 @@ class UserEditPage extends React.Component { applications: [], mode: props.location.mode !== undefined ? props.location.mode : "edit", loading: true, + returnUrl: null, }; } @@ -57,6 +58,7 @@ class UserEditPage extends React.Component { this.getOrganizations(); this.getApplicationsByOrganization(this.state.organizationName); this.getUserApplication(); + this.setReturnUrl(); } getUser() { @@ -100,9 +102,14 @@ class UserEditPage extends React.Component { }); } - getReturnUrl() { + setReturnUrl() { const searchParams = new URLSearchParams(this.props.location.search); - return searchParams.get("returnUrl"); + const returnUrl = searchParams.get("returnUrl"); + if (returnUrl !== null) { + this.setState({ + returnUrl: returnUrl, + }); + } } parseUserField(key, value) { @@ -619,9 +626,8 @@ class UserEditPage extends React.Component { } } else { if (willExist) { - const returnUrl = this.getReturnUrl(); - if (returnUrl) { - window.location.href = returnUrl; + if (this.state.returnUrl) { + window.location.href = this.state.returnUrl; } } }