Skip to content

bug: react-router, page that mounts during navigation is hidden when a sibling catch-all route matched the previous pathname #31696

Closed

Description

@ptmkenny

Prerequisites

Ionic Framework Version

v9.x

Current Behavior

When a page mounts in the same commit as a navigation, and the outlet has a catch-all
(*) route that matched the previous pathname, the new page is hidden. The screen is
blank. No error is thrown.

The entering page stays in the DOM like this:

<div class="ion-page ion-page-hidden" aria-hidden="true">…</div>

A common trigger is logout: an anonymous-only route guard renders the login page as soon
as the user is cleared, and the logout handler calls navigateRoot('/login') in the same
tick.

Expected Behavior

The page for the new pathname is shown, as it is when the page mounts after the
navigation.

Steps to Reproduce

  1. Clone the reproduction, check out register-stale-routeinfo, then run
    npm install and npm run dev.
  2. Open /join. The Join page is shown.
  3. Press Log in. The app sets the user to logged in and calls
    router.push('/verify', 'forward').
  4. Press Log out. The app calls setLoggedIn(false), then
    router.navigateRoot('/join').
  5. Observe: the screen is blank. The status bar at the bottom of the page reports
    last: hidden. In the DOM, the Join page is in the inner ion-router-outlet with
    ion-page-hidden and aria-hidden="true".

It reproduces on every logout (10/10 runs in Chromium). It does not depend on React
Router's v7_startTransition future flag: the result is the same with and without it.

The route shape is:

<IonRouterOutlet>
  <Route path="/verify" element={<VerifyPage />} />
  <Route path="*" element={
  <Route path="/verify" element={<VerifyPage />} />
  <Route path="*" element={
    <IonPage>
      <IonRouterOutlet>
        <Route path="/join/*" element={<GuardAnonOnly><JoinPage /></GuardAnonOnly>} />
        <Route path="*" element={<NotFoundPage />} />
      </IonRouterOutlet>
    </IonPage>
  } />
</IonRouterOutlet>

GuardAnonOnly renders its child only while logged out.

Code Reproduction URL

https://github.com/ptmkenny/ionic-react-router-6-test/tree/register-stale-routeinfo

Ionic Info

Ionic:

   Ionic CLI       : 7.2.1 (/home/node/.npm/_npx/f6fddb685269761d/node_modules/@ionic/cli)
   Ionic CLI       : 7.2.1 (/home/node/.npm/_npx/f6fddb685269761d/node_modules/@ionic/cli)
   Ionic Framework : @ionic/react 9.0.10

Capacitor:

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

Utility:

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

System:

   NodeJS : v26.13.0 (/usr/local/bin/node)
   npm    : 11.20.0
   OS     : Linux 6.18

Additional Information

I used AI (Opus 5.5) to prepare this issue report and reproduction.

Root cause

routeInfo trails the location. IonReactRouter passes a location change to
IonRouter from a useEffect, and IonRouter then calls setRouteInfo, which takes
another render. A page that mounts in the same commit as the navigation therefore calls
registerIonPage(page, routeInfo) with the previous pathname.

In the reproduction:

  1. While the user is on /verify, the inner outlet (still mounted under the hidden *
    page) has two view items: /join/*, whose page unmounted when the guard stopped
    rendering it, and *, holding NotFoundPage for /verify.
  2. On logout, the guard renders JoinPage in the same commit as the navigation. The new
    IonPage registers with routeInfo.pathname === '/verify' while the URL is already
    /join.
  3. StackManager.registerIonPage calls findViewItemByRouteInfo(routeInfo, this.id). In
    the inner outlet only the * route matches /verify, so the Join page becomes the *
    view's ionPageElement, replacing NotFoundPage.
  4. When routeInfo reaches /join, ReactRouterViewStack.renderViewItem deactivates
    the * view because the more specific /join/* route matches, and adds
    @
    the * view because the more specific /join/* route matches, and adds
    ion-page-hidden and aria-hidden="true" to that view's ionPageElement, which is
    now the Join page. The /join/* view has no page element, so nothing is shown.

A trace of the lookups during logout (instrumented in the browser):

REG  routerOutlet-4 [Join page] ri=/verify live=/join
FIND routerOutlet-4 ri=/verify -> *        via StackManager.registerIonPage
FIND routerOutlet-4 ri=/join   -> /join/*  via StackManager.findViewItems

The existing orphaned-page check (shouldRejectOrphanedPage, from #28878) does not
apply: it compares data-pageid values and the outlet's own routeInfo, and here the
outlet's routeInfo is stale too.

Activity

  1. thetaPC commented on Nov 5, 2026

    @thetaPC
    Contributor

    Thanks for the report.

    Verified on 9.0.10. IonPage registers with Ionic's route info, which only updates in an effect after React Router's location changes. When the guard renders the Join page in the same commit as navigateRoot('/join'), the page registers against /verify, so the inner outlet hands it to the * route that matched /verify. Once the route info reaches /join, the more specific /join/* route wins and the * view's page, which is now the Join page, gets hidden. Your trace is correct.

    Workaround, verified on 9.0.10 with and without v7_startTransition: navigate first, then clear the user in a later task, so the guard renders the Join page after Ionic's route info has caught up:

    const logOut = () => {
      router.navigateRoot('/join');
      setTimeout(() => setLoggedIn(false));
    };

    Tracked as a bug in @ionic/react-router.

  2. added
    package: react
    type: bug
    on Nov 5, 2026
  3. added a commit that references this issue on Nov 10, 2026
    c6680bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: reacttype: bug

    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