简体   繁体   中英

How to stay on the Current Page in JavaScript after refresh

guys!

I am working on a project with Java + Javascript and when I refresh the page instead of staying in my home page, it's redirecting to login page.

I'm new to this and want to know how can I stay on same page after refreshing. I read some examples but it's not clear how to achieve this.

Example: if I'm in Settings page and press F5 or reloa, I wanna stay in Settings Page.

.preventDefault can be used on event listeners to avoid refreshing The event listener can be anything that causes the refresh

Typically location.reload(); would be used to refresh to the same URL, but your application logic might only allow access to particular URLs after going through certain other steps - eg logging in.

Without more information, your question will be almost impossible to answer.

You should try to figure out the steps that your application goes through during a bootstrap (ie start-up), as refreshing in a web app is effectively a restart of the JavaScript application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM