History.replaceState/pushState changed the url, but the address bar did not change the problem.

now the company has a project and a requirement that when logging in from an external URL, it will be automatically redirected to the home page, as follows:
http://localhost:8889/?sessionId=4724-3551655957868--736132069sh-sharp!/app/home, then you need to take out the previously saved destination URL (such as the destination URL is the dashboard page) and redirect to the destination URL, such as window.location.href= "http://localhost:8889/app/dashboard". It is now required that the URL must not contain sessionId. After redirecting to the dashboard page, the URL is http://localhost:8889/-sharp!/app/dashboard, is normal, there is no sessionId;, but when the user clicks the browser back button, go back to the home page, where the URL is http://localhost:8889/?sessionId=4724-3551655957868--736132069sh-sharp!/app/home. In order to resolve the problem of session in the URL when fallback to the home page.

my current idea is that when users redirect from the login page to the home page, use the window.history.replaceState ({}, "http://localhost:8889/-sharp!/app/home"), of the history object to change the url of the current path to http://localhost:8889/-sharp!/app/home, so that when the user clicks the browser back button from the dashboard page, the URL no longer contains session.

however, after I used the above action in case of a problem, I even jumped to the dashboard page and became http://localhost:8889/?sessionId=4724-3551655957868--736132069sh-sharp!/app/dashboard. I wonder why the address bar hasn"t changed after changing the browser history list.
there are students who know, please give me some advice, thank you!

Mar.19,2021

look at the last http://localhost:8889/?sessionId=4724-3551655957868--736132069sh-sharp!/app/dashboard result. I guess it has something to do with the mode that you are using hashtag (-sharp ). If you are using the ordinary path http://localhost:8889/app/home, there will be no problem.

your way of thinking is not wrong, probably window.history.replaceState can not be used in this way, you have to check MDN.


Today, we found another API, window.location.replace , which can solve the above problems. The effect is very good @ array_huang . For more information, please see here

.
Menu