How to set history programmatically?

A user is now on page 1, from there he enters to page 2 and from there he enters to page 3.
He’s doing something in page 3 that the system auto moves him back to page 2 (since page 3 after his action is not relevant any more), so now he back to page 2.
I want that from page 2, by the time he clicks the back button, to return to page 1, not page 3.
How this could be done?

I think if you use the regular Framework7 router api methods, that is the default way it works? It’s not advised to manually modify the router history.

1 Like

Router Methods
router.navigate(url, options) Navigate to (load) new page

  • url string - url to navigate to
  • options - object with additional navigation properties (optional):
    • clearPreviousHistory (boolean) - previous pages history will be cleared after reloading/navigate to the specified route
    • history (boolean) - whether the page should be saved in router history

Also,

He’s doing something in page 3 that the system auto moves him back to page 2

I think that you are navigating to page 2 from page 3. instead of .router.navigate() try with router.back()

router.back(url, options)	Go back to previous page, going back in View history

this way, page 3 will not be on history just page1 and 2

2 Likes