Clear history on PageInit

Hi All,

I have a scenario where i need to clear all history on event of particular router.

I tried to clear history using query which is not working.

{
     path: '/',
     url: './index.html',
     name: 'home',
     on:{
         pageAfterIn: function() {
             app.view.main.history.pop();
             $('.page-previous, .navbar-previous').remove();
         }, pageInit: function(){
             app.view.main.history.pop();
             $('.page-previous, .navbar-previous').remove();
         }
 }

@nolimits4web Can any one help on this?

Don’t really understand what you are trying to achieve but there is a reloadAll option that you can pass to router.navigate. It will clear the history and load the page as the only one

Hi @nolimits4web,

In my case when user come to home page, then he shouldn’t go back.

I am using anchor tag for navigation. so user can come to home page form any other page like below.
eg;
home page -> page1 -> home page
home page -> page1 -> page2 -> home page
home page -> page1 -> page2 -> page3 -> home page
home page -> page2 -> page3 -> home page
home page -> page3 -> home page

I can’t put router.navigate on all pages because it should support history back for other pages.

This is works for me:

$('.page-previous, .navbar-previous').remove();
app.view.main.history = ['/']; // url of the home pagec
app.view.main.router.history = ['/'];

Check the 2.0.10 release, there is a new clearPreviousHistory router method and app parameter that can remove all previous pages

Hi @nolimits4web,

I tried with app.router.clearPreviousHistory=[]. But still no luck… When i use app.router.back() still application going previous page

It is a method app.router.clearPreviousHistory()

1 Like

Hi @nolimits4web,

When i am calling app.router.clearPreviousHistory() its giving below error.

framework7.js:7193 Uncaught TypeError: Cannot read property 'length' of undefined
    at t.clearPreviousHistory (http://framework7.io/dist/js/framework7.min.js:12:105739)
    at <anonymous>:1:12clearPreviousHistory @ framework7.js:7193(anonymous function) @ VM84:1

Hi @nolimits4web,

Can you help to resolve this. All my app functionalities depends in this.

How do you use it? Try also

<a href="/" data-clear-previous-history="true">Home</a>
1 Like

Hi @nolimits4web,

Thanks for your quick reply…

I can implement given snippet half places only.

Is there any way to clear history on particular pageInit event using js?

Not on pageInit, but can be on pageAfterIn

@nolimits4web,

That’s fine for me… Can you tell how we can achieve this on pageAfterIn

While i am trying app.router.clearPreviousHistory() its giving above mentioned error

This is what is perfectly works in Kitchen Sink:

  {
    path: '/',
    url: './index.html',
    name: 'home',
    on: {
      pageAfterIn(e, page) {
        page.router.clearPreviousHistory();
      },
    },
  },
3 Likes

Perfect @nolimits4web:tada:

thanks @nolimits4web your code work for me. Made my day.
Thank you so much