Skip to content

bug: tabs do not work correctly when using pages outside tab routes #27847

Description

@darrylnoakes

Prerequisites

Ionic Framework Version

v6.x

Current Behavior

I am using Vue and Ionic 6.7.5.
Tabs do not work correctly when using pages outside tab routes.

This is the relevant route config:

const routes: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: { name: "Index" },
  },
  {
    path: "/",
    component: MainPages,
    children: [
      {
        path: "",
        redirect: { name: "Index" },
      },
      {
        path: "index",
        name: "Index",
        component: IndexPage,
      },
      {
        path: "playlists",
        name: "Playlists",
        component: PlaylistsPage,
      },
      {
        path: "playlists/:id",
        name: "Playlist",
        component: PlaylistViewerPage,
      },
    ],
  },
  {
    path: "/settings",
    name: "Settings",
    component: SettingsPage,
  },
  {
    path: "/song/:id",
    name: "Song",
    component: SongViewerPage,
  },
];

The structure is:

Tabs
  Song Index
  Playlist Index
    Playlist Viewer
Song viewer
Settings

The playlists page has a list of playlists which can be viewed using the shared-route view. This view has a list of songs that can be pushed to. The song-viewing view is external to the tabs.

Page lifecycle events

The app starts on the index page. Navigating to the playlists page, a playlist, a song, and back (any method) does not trigger the playlist-viewing page's view entering event.
Index -> Playlists -> Playlist [nested] -> Song [external to tabs] -> (back) Playlist
The paths are:

  • /index
  • /playlists
  • /playlists/xxx
  • /song/yyy
  • /playlists/xxx

After leaving the nested view (going back to the root view of the playlist tab), it works fine. Switching to the other tab and back also fixes it.
Leaving the nested view and coming back -- before doing anything else -- prevents the issue.
Starting on the playlists tab does not manifest the issue; however, going to the index tab sets the stage for it.
A complex orchestration of history state.

A button that navigates to the settings page is present on all the pages. This exhibits the same behavior when using it from the nested view.

The behavior does not appear to manifest when navigating to and from the external views directly from the root tab views; only from the nested view in the playlist tab.

Also, view leaving events are never triggered when navigating to a view external to tabs.

Tab navigation state

Navigating to a nested view in a tab, switching tabs, navigating to an "external" view, and going back clears the state of the first tab.

In this case:

  • Go to playlist tab.
  • Go to playlist viewer (in playlist tab).
  • Switch to index tab.
  • Go to song viewer (external-to-tabs view).
  • Go back.
  • Switch to the playlists tab.

The playlist tab shows the playlist index instead of the playlist viewer.

Expected Behavior

I expect to be able to use pages external to the tab routes.

Specifically:

  • I expect page lifecycle events to always fire.
  • I expect tabs to maintain their individual navigation state.

Steps to Reproduce

  1. Create a tabbed Vue application with the route structure like the one described above. Include logging of the page lifecycle events.

  2. Load the app on the index page. Navigate to the playlists page, a playlist, a song, and back (any method).
    Index -> Playlists -> Playlist [nested] -> Song [external to tabs] -> (back) Playlist
    The paths are:

    • /index
    • /playlists
    • /playlists/xxx
    • /song/yyy
    • /playlists/xxx

Code Reproduction URL

darrylnoakes/ionic-27847

Ionic Info

Ionic:

   Ionic CLI       : 6.16.3 (C:\Users\Darryl\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework : @ionic/vue 6.7.5

Utility:

   cordova-res : not installed globally
   native-run  : not installed globally

System:

   NodeJS : v18.15.0 (C:\Users\Darryl\AppData\Local\Volta\tools\image\node\18.15.0\node.exe)
   npm    : 9.5.0
   OS     : Windows 10

Actually Windows 11.

Additional Information

Is this the correct behavior or a bug? Is it a known or unknown issue?
I do not know if this is an issue in Ionic 7.


Related issues:

Possibly related:


Video of reproducing the lifecycle events issue:

Repro.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions