You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current behavior:
When I navigate back with an ion-back-button on a tabs template I always end up on the root page.
How do I solve this?
Expected behavior:
I expect it to navigate back to the site I was before and NOT to the root page.
Steps to reproduce:
$ ionic start
Select the tabs template
$ ionic generate page [your page name here]
Add a ion-button to tab2
Add: (click)="go()" to the button.
Add: constructor(public router: Router){}
Add: import { Router } from '@angular/router';
Define go() in the TypeScript file like this:
go() {
this.router.navigate(['yourpagename'])
}
On the generated Page add in the toolbar an ion-back-button
$ ionic serve -l
Other information:
The src folder of my App: src.zip
Ionic info:
Ionic:
ionic (Ionic CLI) : 4.10.2
System:
NodeJS : v10.15.0
npm : 6.4.1
OS : Windows 10
Reacted by Franc Muñoz, CitizenOfEarth, Nicolas Falla, Miguel Nunes Correia, LeoZhang, zxdeer, Mau Muñoz, Bao Pham, Mathias Lykkegaard Lorenzen, hassan-1993 and 1 more
I'm having the same issues occur only with tabs pages but if I navigate from regular page into any page and hit the back button it work as expected the same page if I navigated from tab page and hit the back button i end up in the root page
defaultHref only comes into play when you navigate directly to that page because it doesn't know the stack.
I'm also having this issue but I'm using ion-segment that changes based on url which I suppose is the same thing as tabs. I have not found a solution yet.
same issue,I resolve this issue with routerDirection , eg:<ion-button routerLink="/path/to/page" routerDirection="back"><ion-icon name="arrow-back"></ion-icon></ion-button>
Obviously, if the page is accessible from more than one parent, I would need to be a bit smarter about that, but doing so is a relatively trivial exercise.
@kensodemann When you navigating back like this, you will lose the state inside your tabs. This is because internally it navigates back to /tabs and then to the route specified in your (click) function.
same issue,I resolve this issue with routerDirection , eg:<ion-button routerLink="/path/to/page" routerDirection="back"><ion-icon name="arrow-back"></ion-icon></ion-button>
Child page repeatedly jump still can not return to the main page
If I am coming from another page e.g. SomePage and then pushing a tabbed page "onto the stack" this.navController.navigateForward('tabs/tab1') and then click on the back button, I would expect to get back to SomePage however that is not what is happening at the moment. Instead I land at the tabs page instead of at the page where I came from.
If I use the browsers back button I do in fact get the desired behaviour (getting back to SomePage).
I guess this is because "back" first sends me back to the tabs page (on step back).
So the issue might be that navigating to tabs/tab1 is actually creating 2 pushes onto the "back stack" instead of one?
I don't fully get it.
Sadly neither of the solutions above worked for me yet. (or I did something wrong)
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Activity
3alampro commentedon Feb 8, 2019
I'm having the same issues occur only with tabs pages but if I navigate from regular page into any page and hit the back button it work as expected the same page if I navigated from tab page and hit the back button i end up in the root page
Caturix2199 commentedon Feb 8, 2019
Same issue here. Also tried to update angular/router. Didn't change anything.
sukheja-varun commentedon Feb 8, 2019
Can you try this
CitizenOfEarth commentedon Feb 9, 2019
@sukheja-varun it doesn‘t work
At defaultHref I tried many things:
/
/tab2
tab2
/tabs/tab2
tabs/tab2
Nothing works
sukheja-varun commentedon Feb 9, 2019
Can you please check which ionic version is installed.
Use below command on your project terminal
npm list @ionic/angularkyleabens commentedon Feb 9, 2019
defaultHref only comes into play when you navigate directly to that page because it doesn't know the stack.
I'm also having this issue but I'm using ion-segment that changes based on url which I suppose is the same thing as tabs. I have not found a solution yet.
thenaim commentedon Feb 9, 2019
same issue #15216 ?
CitizenOfEarth commentedon Feb 12, 2019
@sukheja-varun I did the command and this was the output:
-- @ionic/[email protected]
442623641 commentedon Feb 27, 2019
same issue,I resolve this issue with
routerDirection, eg:<ion-button routerLink="/path/to/page" routerDirection="back"><ion-icon name="arrow-back"></ion-icon></ion-button>kensodemann commentedon Feb 27, 2019
@442623641 - I have been being intentional about where I go back to, like this:
Obviously, if the page is accessible from more than one parent, I would need to be a bit smarter about that, but doing so is a relatively trivial exercise.
servrox commentedon Mar 4, 2019
@kensodemann When you navigating back like this, you will lose the state inside your tabs. This is because internally it navigates back to
/tabsand then to the route specified in your(click)function.I also created a custom ionic component to cover the relatively trivial exercise.
See my solutions to navigate back without losing tab-states.
zxdeer commentedon Mar 8, 2019
Child page repeatedly jump still can not return to the main page
wkande commentedon Mar 21, 2019
Works with or without routerDirection="back" not sure why or if it is needed
Eraldo commentedon Apr 10, 2019
If I am coming from another page e.g.
SomePageand then pushing a tabbed page "onto the stack"this.navController.navigateForward('tabs/tab1')and then click on the back button, I would expect to get back toSomePagehowever that is not what is happening at the moment. Instead I land at the tabs page instead of at the page where I came from.If I use the browsers back button I do in fact get the desired behaviour (getting back to
SomePage).I guess this is because "back" first sends me back to the tabs page (on step back).
So the issue might be that navigating to
tabs/tab1is actually creating 2 pushes onto the "back stack" instead of one?I don't fully get it.
Sadly neither of the solutions above worked for me yet. (or I did something wrong)
Insights are welcome. ;)
wkande commentedon Apr 10, 2019
Here is another idea using angular/common.
liamdebeasi commentedon Apr 10, 2019
Hi there,
This issue has been resolved, and I have published a nightly build of Ionic with the fix. You can install it with
npm i @ionic/angular@dev.Please let me know if you are still running into any issues with this.
Thanks!
ionitron-bot commentedon May 10, 2019
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.