I am trying to reload a page on clicking the back, forward or reload button in the browser.
Below are the use-cases:
1.User enters details in the signup form and submits -> the same page shows up with an OTP form. If this page is revisited using the back, forward, or reload button, it should be redirected to the first page with an empty signup form.
2.User submits the cart form -> moves to the checkout page and submits form -> moves to payment gateway. If the Checkout page is revisited using the back, forward, or reload button, it should be redirected to the cart page. Redirects are happening to the Cart page if I copy-paste the Checkout page to the browser, based on the type of request, GET or POST
I want this similar to Instagram signup, where the user fills the Signup form and goes to the OTP form. If the user reloads or revisits the OTP form, he is redirected to the original Signup form. Also, the tab history stack only has one page for both Signup and OTP forms
I tried using PerformanceNavigationTiming.type but it's not working. Below is the code.
var perfEntries = performance.getEntriesByType("navigation");
if (perfEntries[0].type === "back_forward") {
location.reload(true);
}
I also tried PerformanceNavigation.type with no success.
Below are the list of pages I want reload for and the PerformanceNavigationTiming.type console.log(performance.getEntriesByType("navigation")[0].type)
for each page on clicking back or forward buttons. All of these pages show up in the browser's tab history stack.
Cart page(/cart) --(POST request)> Order Confirmation page(/confirmcorder) --(POST request)> Payment gateway page(/payment)
back_forward <-- navigate <-- navigate
Home page(/home) --> Signup page for user details(/signup) --(POST request)> Signup page for otp(/signup)
back_forward <-- back_forward <-- navigate
Home page(/home) --> Signup page for user details(/signup) --(POST request)> Signup page for user details-with error(/signup) --(POST request with errors corrected)> Signup page for otp(/signup)
back_forward <-- back_forward <-- navigate <-- navigate
How to solve this issue?