@peterjc wrote:
I am porting my Ionic 3 app to Ionic 4. I have switched over to using the new routing, with lazy loaded modules etc.
I have a side menu where I can select my main pages from any other page.
However, whenever I click the back button from one of the main feature pages, I always want to go back to the main home page (and not back to perhaps another feature page in the current route stack)
The click handler code in the
Ionic 4version for the side menu selection is as follows (pageItem.pageRoutePath contains the new route)public openPage(pageItem: AppPageItem): void { try { this.logger.debug(`openPage ${pageItem.title}`); // Try to force homepage to be where the back button takes us (but this doesn't seem to work) this.navController.navigateRoot(Constants.vals.pageRoutePaths.home, { replaceUrl: true }); if (pageItem.pageRoutePath != Constants.vals.pageRoutePaths.home) { this.navController.navigateForward(pageItem.pageRoutePath); } } catch (error) { this.logger.error(`openPage ${error}`); } }The
{ replaceUrl: true }parameter was me experimenting trying to get this to work, but it did not make any difference.In
Ionic 3I could do what I am describing as follows…this.nav.setRoot(HomePage); if (pageItem.page != HomePage) { this.nav.push(pageItem.page); }I don’t want this from every page, just my feature pages, eg some of the feature pages navigate to "details: pages, and here I do want the back button to just return back to the page it was navigated from, ie the default behavior. Also, I do have one feature page where I do open it as a details fro another feature page, so in this case i do want the detail behaviour of the back button.
So, I just really want to switch the behaviour when the page is opened from this side menu.
Does anyone know how I can achieve this in
Ionic 4?Thanks in advance for any help
Posts: 1
Participants: 1