How to check for current page with ons-navigator (Onsen UI)

328 Views Asked by At

Im trying to figure out how to check what page im on when doing a popPage() using onsen uis ons-navigator. I tried the following but they all always return false no matter what:

this.navigator.nativeElement.popPage().then((page: any) => {
  console.log("instanceof:", page instanceof BrowsePageComponent);
  console.log("typeof:", page instanceof BrowsePageComponent);
  console.log("isBrowsePage:", page === BrowsePageComponent);
  console.log("isBrowsePage:", page == BrowsePageComponent);
});

A little Context: Navigator is being referenced in my angular app like this:

@ViewChild('navigator') navigator: ElementRef;

After debugging this, i noticed page seems to definitely hold a reference to the page that its navigating to. I just cant figure out how to check if im on a particular page.

1

There are 1 best solutions below

0
SanzioSan On

I solved this by using the pushedOptions object. It holds a reference to the page class:

this.navigator.nativeElement.popPage().then((page: any) => {
    const currentPage = page.pushedOptions.page;
    if(currentPage === BrowsePageComponent){
      console.log("Im on the browse page.");
    }
  });