0

I have a back button in page C, when I visit page C from page A, the back button return me to page A, when I visit page C from page B, the back button returns me to page B. However, if I'm on page C and refresh it then the back button doesn't work anymore because it doesn't detect the previous page. So how can I return to the previous page even after refresh next page?

Here is my code but not work around:

backClicked() {
    // Check if page is refresh
    if (performance.navigation.type === 1) {
      // Try to recall the previous page before refresh (but not work)
      location.replace(document.referrer);      
    } else {
      // return to prev page based on history
      window.history.back();
    }
  }
Hoàng Nguyễn
  • 1,121
  • 3
  • 33
  • 57

0 Answers0