Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: switching between shared tab urls does not preserve individual tab stack history #25213

Open
4 of 7 tasks
philmmoore opened this issue Apr 28, 2022 · 26 comments
Open
4 of 7 tasks
Labels
package: vue @ionic/vue package type: bug a confirmed bug report

Comments

@philmmoore
Copy link

philmmoore commented Apr 28, 2022

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x
  • Nightly

Current Behavior

Within an application we may want to switch from one tab to another to see what information is on the other tab.

If I am on Tab 2 and navigate to a child route /tabs/tab2/view then tap on Tab 3 from the tab bar and again navigate to a child route within Tab 3 /tabs/tab3/view I am able to switch between Tab 1, 2 and 3 and the correct views are displayed

Simulator.Screen.Recording.-.iPhone.12.Pro.-.2022-04-28.at.20.57.19.mp4

If I then navigate to Tab 3 and press back (uses IonBackButton) the view will correctly navigate back.

Simulator.Screen.Recording.-.iPhone.12.Pro.-.2022-04-28.at.20.59.03.mp4

But If I then go to Tab 2 from the tab bar you'll notice that on Tab 2 I no longer have a back button and can no longer get back to the preview view.

Simulator.Screen.Recording.-.iPhone.12.Pro.-.2022-04-28.at.21.00.56.mp4

Tabbing to Tab 1 or 3 does not help. Only tapping the tab on the tab bar quickly does anything but you then have to navigate away and back again.

Simulator.Screen.Recording.-.iPhone.12.Pro.-.2022-04-28.at.21.02.03.mp4

Expected Behavior

I would expect to be able to navigate to child routes within tabs and each nav stack work independently so that I could travel X number of levels deep in Tab 2 then Tab into Tab 3 and again travel X number of levels deep. If I then wanted to get back to the root view for the tab I would either tab the tab bar quickly to 'popToRoot' or use the IonBackButton within each child view to make my way back up.

Steps to Reproduce

Repro steps should be pretty self explanatory based on the videos shown in the current behaviour.

Simulator.Screen.Recording.-.iPhone.12.Pro.-.2022-04-28.at.21.13.06.mp4
  1. Tab to Tab 2
  2. Tap Go to view
  3. Tab to Tab 3
  4. Tap go to view
  5. Tab back to Tab 2 and press the back button
  6. Tab back to Tab 3 and you'll see the back button has gone
  7. Double tap Tab 3 (notice there's a slight flicker in the video above)
  8. Tab back to Tab 2 and then straight back to Tab 3
  9. Notice that you're now back on the root view for the tab

Code Reproduction URL

https://github.com/philmmoore/ionic-tabs-bug

Ionic Info

Ionic:

Ionic CLI : 6.18.1 (/Users/philmmoore/.nvm/versions/node/v16.11.1/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/vue 6.1.3

Capacitor:

Capacitor CLI : 3.5.0
@capacitor/android : not installed
@capacitor/core : 3.5.0
@capacitor/ios : 3.5.0

Utility:

cordova-res (update available: 0.15.4) : 0.15.3
native-run : 1.5.0

System:

NodeJS : v16.11.1 (/Users/philmmoore/.nvm/versions/node/v16.11.1/bin/node)
npm : 8.0.0
OS : macOS Big Sur

Additional Information

No response

@liamdebeasi
Copy link
Contributor

Thanks for the issue. Does this dev build help at all? I am fixing a similar issue in #25206.

npm install @ionic/[email protected] @ionic/[email protected]

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Apr 28, 2022
@ionitron-bot ionitron-bot bot removed the triage label Apr 28, 2022
@philmmoore
Copy link
Author

Hey @liamdebeasi still able to follow repro steps and it fails.

Happy to try any other dev builds when they're ready 👍

Simulator.Screen.Recording.-.iPhone.12.Pro.-.2022-04-29.at.01.03.02.mp4

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Apr 29, 2022
@productdevbook

This comment was marked as off-topic.

@liamdebeasi
Copy link
Contributor

@productdevbook That behavior appears to be unrelated to the issue being discussed in this thread. Please open a separate issue.

@liamdebeasi
Copy link
Contributor

liamdebeasi commented Apr 29, 2022

Hey @liamdebeasi still able to follow repro steps and it fails.

Happy to try any other dev builds when they're ready 👍

Simulator.Screen.Recording.-.iPhone.12.Pro.-.2022-04-29.at.01.03.02.mp4

Thanks for testing! The issue appears to be that when going back to Tab 3 for the second time, the browser is wiping the history. The reason for this is when you go back to Tab 2 (you should be on the Tab 2 child page) and press the ion-back-button, we call router.go() to go back to the previous instance of Tab 2. When you tap Tab 3, we push a new /tabs/tab3/view route which causes the browser to clear its routing history.


The big limiting factor here is that the browser history wants linear navigation. Mobile tabs are non-linear by nature as each tab is its individual stack.

For example, consider the following flow:

/tabs/tab2 --> /tabs/tab2/view --> /tabs/tab3 (tap the Tab 3 button) --> /tabs/tab3/view --> /tabs/tab2/view (tapping the Tab 2 button again).

If you press the ion-back-button you should go back to /tabs/tab2. This is what happens right now.

However, if you press the hardware back button multiple times on an Android device, you should be taken backwards through the following flow:

/tabs/tab3/view --> /tabs/tab3 --> /tabs/tab2. Note that going from /tabs/tab3 brings you to /tabs/tab2 not /tabs/tab2/view. The reason for this is we already popped /tabs/tab2/view off the Tab 2 stack. This does not happen due to the issue I noted above.


Both the issue you noted and the hardware back button issue stem from how we push new routes when switching between tabs. I have a few ideas for how we can solve this, so I am going to talk with the team and see which option is best.

@liamdebeasi liamdebeasi changed the title bug: child routes within tabs not navigating as expected bug: switching between shared tab urls does not preserve tab stack history Apr 29, 2022
@liamdebeasi liamdebeasi changed the title bug: switching between shared tab urls does not preserve tab stack history bug: switching between shared tab urls does not preserve individual tab stack history Apr 29, 2022
@liamdebeasi
Copy link
Contributor

The ion-back-button issue reproduces in Ionic Vue, but the hardware back button issue reproduces across Ionic Angular, Ionic React, and Ionic Vue.

I tested this using the Ionic React Conference App and the Ionic Angular Conference App.

@liamdebeasi liamdebeasi added package: vue @ionic/vue package type: bug a confirmed bug report labels Apr 29, 2022
@ionitron-bot ionitron-bot bot removed the triage label Apr 29, 2022
@philmmoore
Copy link
Author

Hey @liamdebeasi thanks for the explanation, undestood!

Pleased we've got it logged as I've had to rework my app to use ion-nav and pushing views onto its own stack but I'd of course prefer to be able to use the router.

@liamdebeasi
Copy link
Contributor

Quick update: We need to fix #25255 and #24594 before we can fix this issue.

We have a fix in place for #25255, and it is currently being reviewed by the team.

@philmmoore
Copy link
Author

Hey @liamdebeasi do you have an idea of when this issue might get worked on again, it's really preventing me from creating tabbed applications with nested routes.

Cheers

@mannok
Copy link

mannok commented Aug 25, 2022

@liamdebeasi Hello, may I know will this be fixed? Thanks.

@liamdebeasi
Copy link
Contributor

We do not provide time estimates of when these issues will be resolved. However, when we do have an update we will post it here.

@torgnywalin
Copy link

Hi, Is this issue still being addressed?
We also have issues with back button showing up and not working in tabs when doing nested navigation in multiple tabs and switching between them.

If i understand this issue right, for now its impossible to make tabbed apps with the vue-router?

@mmoore99
Copy link

Pleased we've got it logged as I've had to rework my app to use ion-nav and pushing views onto its own stack but I'd of course prefer to be able to use the router.

@philmmoore do you have any information and/or code that you could share regarding the approach you used to get around this issue using ion-nav? Thanks.

@mmoore99
Copy link

mmoore99 commented Jun 26, 2023

@liamdebeasi until, when and if, this issue gets resolved there should be a warning in the Vue section of the documentation that using tabs with child views is broken. The inability to have child views in tabs severely restricts the ability to use ionic/vue for many types of apps and developers should be aware of this before going down the road, following the documentation and then running into a big roadblock after a lot of time and effort is expended. The documentation (see quote below) should not be showing this approach as an example of how to architect an application when it is not possible.

This is obviously not a trivial bug since it has been open for quite some time. At the very least please make developers aware of this so they don't waste a lot of valuable time.

Instead, we recommend having routes in each tab that reference the same component. This is a practice done in popular apps like Spotify. For example, you can access an album or podcast from the "Home", "Search", and "Your Library" tabs. When accessing the album or podcast, users stay within that tab. The app does this by creating routes per tab and sharing a common component in the codebase.

@rmnkk
Copy link

rmnkk commented Aug 16, 2023

@liamdebeasi until, when and if, this issue gets resolved there should be a warning in the Vue section of the documentation that using tabs with child views is broken. The inability to have child views in tabs severely restricts the ability to use ionic/vue for many types of apps and developers should be aware of this before going down the road, following the documentation and then running into a big roadblock after a lot of time and effort is expended. The documentation (see quote below) should not be showing this approach as an example of how to architect an application when it is not possible.

This is obviously not a trivial bug since it has been open for quite some time. At the very least please make developers aware of this so they don't waste a lot of valuable time.

Instead, we recommend having routes in each tab that reference the same component. This is a practice done in popular apps like Spotify. For example, you can access an album or podcast from the "Home", "Search", and "Your Library" tabs. When accessing the album or podcast, users stay within that tab. The app does this by creating routes per tab and sharing a common component in the codebase.

I completely agree with you. It definitely must be mentioned in the documentation that child routes in tabs are broken. We have an app that is built on tabs with many child routes in each tab. Hence, ionic vue tabs are broken for use with child routes, we are now unable to continue developing using vue ionic. We have already been developing the app for some time before we stuck on this issue

@Andr9651
Copy link

Andr9651 commented Jan 9, 2024

Has anyone managed to find a workaround for this issue?

@mannok

This comment was marked as off-topic.

@Andr9651
Copy link

Andr9651 commented Jan 10, 2024

I think I've managed to find a simple workaround.
If the ion-back-button component works as expected with routing, then why dont I just override the hardware back button to do the same?
So I looked into the source for ion-back-button and found that it used a function called handleNavigateBack from a supposed "ionRouter" injected from the key "navManager". It didn't match any IonRouter definition I've seen so I looked it up. It turns out, if I understand this comment correctly, that this issue has already been solved, it's just not been fully integrated.

This is what I ended up doing to fix the issue:
(Keep in mind that I don't really know what I'm doing and my project is still rather small so, unforeseen issues might arise. It also only fixes the issue for the android hardware back button, as it doesn't seem to be possible to modify the navigation history in web or PWA scenarios)

I just added this to my tabs page, which based on the hardware back button documentation, should stop the default back button behavior and instead do the same thing as clicking on a ion-back-button component.

import type { createIonRouter } from '@ionic/vue-router/dist/types/router.d.ts';
const ionicNavManager = inject('navManager') as ReturnType<typeof createIonRouter>;

useBackButton(1, () => {
  if (ionicNavManager === undefined || ionicNavManager === null) {
    return;
  }

  ionicNavManager.handleNavigateBack();
});

@liamdebeasi Do you see any obvious issues with this workaround and is there any reason this isn't the default behavior?

@liamdebeasi
Copy link
Contributor

Do you see any obvious issues with this workaround and is there any reason this isn't the default behavior?

The issue is not limited to using the hardware back button as it reproduces when tapping tab buttons too which is why we have not implemented that as a solution. We have some design work for this internally to resolve the issue, and I'll definitely follow up here when we have something that is testable.

@nagbg
Copy link

nagbg commented May 30, 2024

Hi! Has this been fixed yet? Creates big problems for us.

@tonygaglio
Copy link

I am having this same issue, but with React. Is this still being working on?

@martinboca
Copy link

Same error here!

@Andr9651
Copy link

@brandyscarney (sorry if you're the wrong person to mention) Seeing as Liam DeBeasi is no longer a part of the Ionic team, could anyone at the Ionic team confirm that this is still being worked on? I don't mean to be impatient or rude, and I'm sorry if I come off that way, it's just that this feels like a pretty fundamental issue that has persisted for over 2 years now. So any update on progress or status would be greatly appreciated. Have a nice day.

@gottfried-github
Copy link

gottfried-github commented Dec 14, 2024

A related behavior, described here happens with @ionic/vue@^8.0.0.

@joshdonnell
Copy link

Related to here as well here as well.

Is there any update or any ways around this that are currently known?

@sinedik
Copy link

sinedik commented Dec 18, 2024

Dear Ionic Team,

I hope this message finds you well. I am writing to inquire about the current status of [Issue #25213]regarding the preservation of individual tab stack history when switching between shared tab URLs. This issue has been open since April 2022, and I am interested to know if there have been any developments or plans to address it in upcoming releases.

Thank you for your attention to this matter. I look forward to your response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: vue @ionic/vue package type: bug a confirmed bug report
Projects
None yet
Development

No branches or pull requests