locked
navigation using win-backbutton

    Question

  • I have a button on my initial inset page, home.html, that calls:

    WinJS.Navigation.navigate('/pages/class/class.html');

    On class.html, the page it clicks to, I have the standard <button class="win-backbutton back" aria-label="Back" disabled type="button"></button>

    When I click this back button the first time, it works great, sending me back to home.html.  If I click the button on home.html to go to class.html again, hitting the back button takes me back to my first iteration of class.html, not back to home. (class.html changes based on stored variables so it's not just that it's going back to itself, but rather the first instance of itself).

    In other words, when I go from home to class (first time), back to home, to class (a second time), the history appears to be seeing only:

    home,
    class (first time),
    class (second time)

    and not realizing i went to home before the first and second time I went to class.  So it's as if the "back" button isn't itself registering in the history.

    I've read the documentation but it's unclear on the win-backbutton itself.  Any help would be appreciated.

    Friday, February 22, 2013 4:17 AM

All replies

  • Hi,

    By any chance, the second time "class" loads, is it not reloading itself with different parameters? Maybe when "class" receives the second visit, it is firing some redirect to itself which has the effect of adding the page twice to the navigation history.

    The Page Control Navigator often tracks the visits to the pages very well, it's odd that it's backing to the same page unless the page is refreshing or redirecting to itself.

    Friday, February 22, 2013 12:09 PM
  • I can't see how, but if it works as well as you say it does, then maybe something like that is happening.  I know there's a sample of viewing all history, so I'll try to replicate a toggle for that on the page and see what happens.  Thanks for the lead.  Will update.

    Friday, February 22, 2013 8:28 PM
  • Actually, my first belief about what's going on seems to be correct.  When I place a history out put on my initial loading page content (home.html), and do:

    When I go to Home.html -> Class.html -> (back button to) Home.html -> Class.html -> (back button to...which should go to home.html) Class.html -> (click back button again) Home.html

    The history shows as:

    current   /pages/home/home.html

    1            /pages/class/class.html

    2            /pages/class/class.html

    It's completely ignoring that I went back to home.html between views history items 1 and 2 (using the win-backbutton).  And if you think about it, it also ignored the fact that I started off on the home.html page itself, which was the initial view.  Is there something about the home.html page - being the initial page - that it wouldn't register?  Or is there something else about how navigation history that I'm not understanding generally?

    *** MORE INFO ***

    I've placed the history code on the class page too.  This is what I get, in order of when I go there:

    1.) Open app (home.html loaded)     

    current pages/home/home.html

    2.) Click on a class, using WinJS.Navigation.navigate('/pages/class/class.html'), to get to class.html

    1   /pages/home/home.html

    current /pages/class/class.html

    3.) Click win-back to get to home.html again

    current  /pages/home/home.html

    1           /pages/class/class.html

    4.) Click on a class again

    2          /pages/home/home.html

    1          /pages/class/class.html

    current /pages/class/class.html

    5.) Click back again (goes to the previous class page, instead of home like I want it to)

    1 / pages/home/home.html

    current   /pages/class/class.html

    1   /pages/class/class.html

    5.) Click back again (which does go to the home page)

    current   /pages/home/home.html

    1            /pages/class/class.html

    2            /pages/class/class.html

    So it looks like when you go back in step 3, it's just moving you back in the history, instead of adding to the history.  Which I guess sort of make sense, but then it appends the next class to the remainder of the history, meaning that when you hit back the second time, it's not going back to the page accessed before, but the last page on the list.

    Any recommendations to get it to actually work to get me to the previously view page state would be great.

    • Edited by DaPrezJer Friday, February 22, 2013 9:59 PM
    Friday, February 22, 2013 9:46 PM
  • Hi, I had a problem something similar today.  In my case I had the button(which navigates to class.html) in the appbar. If the eventlistener is set in home.html, removing it when navigating out works as intended.
    Friday, May 24, 2013 10:00 AM
  • first question: can you talk in Chinese ?

    second question: how to find a class style like win-backbutton.  example : i need register button, how to write.

    i wait your answer..  my English is badly,so you look look is ok.


    • Edited by 经年 Saturday, December 28, 2013 3:20 AM
    Saturday, December 28, 2013 3:15 AM