Add a back button when there are no pages to go back to

There is a particular page in my app which can be accessed from the app and from outside the app.
To clear things up more, let’s say my app has the pages A, B and C.

Through the app to get to page C the user has to go through A and B. In this case the back button C will take the user back to B. It is also possible for a user to open page C through other means (like clicking a link). In this case, the back button in page C should close the page C and take the user back to whatever they were doing last.

How do I add a back button for the second scenario. A back button when the app doesn’t have other pages to go back to.

Try to check with the NavController, if the current page is the rootPage --> if so show an additional button.

Hi. How do I incorporate the features of a back button onto my own?
Is there an easy way to create your own custom back button?

Same question here: how to implement custom behavior of back button?

Hi. This worked for me:

In your template:

<button (click)="customBack()"></button>

and on your class:

constructor ( private nav:NavController) {}
customBack() {

Thanks for the reply @maggie001.

This works for regular buttons, but if you use ion-navbar, it has back button ‘built in’.
To make it work, theoretically I can see 2 choices: either replace the existing button with the custom one, or call ‘customBack()’ function for exiting button.

Any idea how to do any of these two?