Skip to content

bug: weird routing behavior when view content is changed while navigation #28878

Closed

Description

@legendar

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

When the page content is changed while we push new route, an invalid view is rendered.
In our project, we navigate to the shop menu when the cart is empty. Also we want to show an empty view for the cart if a user opens the cart URL manually. So somewhere in the code we have the following:

function Cart() {
  //...

  const clearCartAndNavigateToMenu = () => {
    clearCart().then(() => {
      push('/menu/')
    })
  }

  if(isCartEmpty) {
   return <EmptyView />
  }

  return (
    // cart content here
  )
}

After navigation the route changed to '/menu/' and we expect to see the menu page. But instead, we see EmptyView although the route has changed.

Expected Behavior

We expect to see correct view when the route is changed.

Steps to Reproduce

Minimal reprodusible example provided in the repo.
STR:

  1. Open Tab2
  2. Click "Go to list page" button
  3. Click "Remove all items and navigate to home" button
  4. The view will flicker double times and you will see the correct URL ('/tab2') but an invalid view 'There no items'reproducible

Code Reproduction URL

https://github.com/legendar/ionic-issues

Ionic Info

Ionic:

Ionic CLI : 7.2.0 (/***/ionic-issues/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 7.6.6

Capacitor:

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

Utility:

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

System:

NodeJS : v18.15.0 (/home/***/.nvm/versions/node/v18.15.0/bin/node)
npm : 9.5.0
OS : Linux 5.15

Additional Information

After further debugging I found that there is double animation and the reason why this happens is this line in Ionic Router:

this.handlePageTransition(routeInfo);

Before clearing the list we have the following components structure:

Route -> Tab2Nested -> IonPage -> IonContent

when we clear the list Tab2EmptyView view will be rendered and the next components structure is:

Route -> Tab2Nested -> Tab2EmptyView-> IonPage -> IonContent

this change causes the IonPage component remounting, registerIonPage call in IonicRouter and extra page transition.
Alongside we trigger navigation to the home/Tab2 page and as a result, we have two different transitions at the same time.
And this is why we have inconsistency between the route path and rendered view.

So we need to somehow prevent transition to the same page and/or prevent to call several transitions at the same time.

As a workaround we can move IonPage to Tab2Nested so we will have a similar component structure before and after removing a cart:

Route -> CartDetail -> IonPage -> IonContent ->
Route -> CartDetail -> IonPage -> Tab2Nested -> IonContent
if(items.length === 0) {
  return <IonPage><Tab2EmptyView /></IonPage>
}

In this case IonPage will not be remounted and we will not have an extra transition.

Activity

  1. brandyscarney commented on Mar 18, 2024

    @brandyscarney
    Member

    Thank you for the issue and the reproduction! I was able to reproduce the behavior you reported. I have created an internal ticket to investigate this further. 🙂

  2. added
    needs: investigation
    and removed on Mar 22, 2024
  3. removed their assignment
    on Jun 26, 2024
  4. ShaneK commented on Dec 15, 2025

    @ShaneK
    Member

    Hey @legendar ! Thnak you so much for the issue report. I've created a PR that I believe will fix this after our RR6 release. If you'd like to test it, I took the liberty to create a migration for your reproduction so that I could verify this works. The RR6 reproduction is at:

    https://github.com/ShaneK/ionic-react-router-nav-issue/tree/react-router-6 (note the branch - main is just a V8 migration)

    If you'd like to verify the fix, the current dev build is:

    8.7.13-dev.11765829391.14bc580c
    
  5. self-assigned this
    on Dec 15, 2025
  6. added a commit that references this issue on Dec 16, 2025
    9dd2da5
  7. thetaPC commented on Oct 23, 2026

    @thetaPC
    Contributor

    Thanks for the report, and sorry for the delay.

    Verified as fixed on 9.0.9. When Tab2Nested switched from its list IonPage to the IonPage inside Tab2EmptyView during the push, Ionic 8 and earlier treated the newly mounted page as a navigation of its own. That transition finished after the one to /tab2, so the empty view stayed on top even though the URL had changed. #30867 fixed this as part of the React Router 6 support that shipped in v9.0.0. Upgrading to Ionic 9 (which also moves @ionic/react-router to React Router 6) resolves it with no changes to your code.

    If you need to stay on Ionic 8 for now, the workaround from the original report works: keep a single IonPage in Tab2Nested and switch only its content, so the page never remounts:

    return (
      <IonPage>
        <IonContent>
          {items.length === 0 ? <EmptyContent /> : <ListContent items={items} />}
        </IonContent>
      </IonPage>
    );

    Closing this as completed.

  8. ionitron-bot commented on Nov 22, 2026

    @ionitron-bot

    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.

  9. locked and limited conversation to collaborators on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

needs: investigation

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions