How to Create Your Own Page Stack

Asked 2 years ago, Updated 2 years ago, 93 views


Top page as A A→B→C
transition and
A→X→Y
There is a transition called .
You can use pushPage() and popPage() respectively.

I would like to transition from C to Y this time, but I would like to transition back as follows.
But I don't know how to do that.
C→Y→X→A(TOP)

Is there any way to make your own page stack?It would be helpful if the method does not depend on AngularJS.
(*If you go back from C to TOP, it will be solved…)

monaca onsen-ui

2022-09-30 20:18

1 Answers

If you transition from page C to page Y, you can accomplish this by removing page B and page C in the page stack and inserting page X.

See also the ons-navigator documentation.
https://ja.onsen.io/v2/docs/js/ons-navigator.html

ons.ready(function(){
  document.querySelector("#navigator").addEventListener("postpush", function(e){
    // Did you transition from page-c to page-y?
    if((e.leavePage.name=="page-c.html")&(e.enterPage.name=="page-y.html"){
      var navi=e.navigator;
      // 4 pages in the stack?
      if(navi.pages.length==4){
        // Delete Page C
        navi.pages[2].remove();
        // Delete Page B
        navi.pages[1].remove();
        // Insert Page X
        navi.insertPage(1, "page-x.html");
      }
    }
  });
});


2022-09-30 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.