Is there a way to construct the history when accessing a deep link?
For instance when reloading the url /trips/africa/casablanca
the ion-back-button should display and go back to /trips/africa
and then to /trips and finally to /home
Hello.
You must specify defaultHref
property of ` ion-back-button; When you go straight to a page and press back button you will get the expected behavior.
According to official documentation:
defaultHref
Description The url to navigate back to by default when there is no history.
Regards
Thanks! I missed that in the doc! It worked like a charm!
Does the hardware back button work in this case?
Yes, hardware back button also perform same work.
In my opinion it doesnât work. Please reproduce these steps:
- Open app on Android device
- Navigate to any page (home -> any page)
- Refresh the app (I go to chrome://inspect, open app and click f5)
- back button in top left corner works but hardware back button doesnât
Use this inside your home page constructor do like below
this.platform.backButton.subscribe(() => {
this.closeCounter++;
console.log(this.router.url);
if (this.router.url == â/homeâ) {
if (this.closeCounter == 2) {
navigator[âappâ].exitApp();
} else {
this.presentToast();
}
}
else {
//go back
this.router.navigateByUrl("/home");
}
});
cheers!!