Close all opened pages

Hi!
When my app receives a push notification I want to be able to open a specific page.
I need to close all opened pages before to avoid duplicates and keep other restrictions I need for the app flow.

How can I do this?

Hi, router has a method for this;

router.clearPreviousHistory() Clear router previous pages history and remove all previous pages from DOM

Be aware that if you dont have a link to home, just a back button link user will be stuck at the specific page you send it to.

So what i would do is.
First send user to home, then call router.clearPreviousHistory(), this will remove all pages from fom and clear history, as documentation says (just tested it). and then send user to specific page you want. In this case if the user click back button, it will be routed to home.

Documentation
https://framework7.io/docs/view.html#router-api-methods-properties

1 Like

Thanks I tried this before, but wasn’t able to figure out how to get it working the right way.

How did you access the router?
I tried app.router.clearPreviousHistory() and receive a

Cannot read property 'length' of undefined at t.clearPreviousHistory

exception.

Edit: Looks like view.router.clearPreviousHistory() seems to work

1 Like

So its working now as you expected?

Not yet, no. I suspect that app.router.navigate uses a timeout or something so that there is a certain delay.

When I have page A opened, then navigate to home, clear the history and navigate to page B, page B is never opened and I can use the back button to navigate back to A which seems to be the new root of my history.

This will reload new page and remove previous history, e.g.:

app.views.main.router.navigate('/about/', {reloadAll: true})

Also look at navigate options here http://framework7.io/docs/view.html#router-api-methods-properties

1 Like