HTML realizes jumping to the specified page after login without going back

I recently developed a page that needs to implement the login function. After success, I will jump to the specified page. I tried several ways to redirect the page before, but they all failed. Fortunately, I finally succeeded in redirecting, and the browser will not go back, so here Take a note:

At the beginning, I used window.location.href=" http://localhost:8080 ", although I could successfully jump to the specified page, but clicking the back button of the browser will return to the login page, which leads to the login page and the main page can be switched back and forth, so that the login function is equivalent to no effect

So I switched to window .location.replace(' http://localhost:8080 '); the browser's fallback function is locked, and after the login is successful and jumps to the main page, it cannot be rolled back

window.location.replace('http://localhost:8080' + window.location.search);

Later, I learned about the difference between window.location.href and window.location.replace. window.location.href locates the specified url from the current page, and its essence is to change the address location of the browser. A record of a page, window.location.replace is to replace the url in the current cache and history with the specified url, which can no longer be accessed by forward and backward, and the replaced page is very suitable for developing transitional pages such as login pages

Guess you like

Origin blog.csdn.net/weixin_45392969/article/details/129498070