Skip to content

bug: Using React Router <Switch> breaks passing state as child props #31157

@mjog

Description

@mjog

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

This is identical to #19986 except with a Switch element inserted into the outlet:

const App: React.FC = () => {
  const [name, setName] = useState('Viktor');
  return (
    <IonApp>
      <IonReactRouter>
        <IonTabs>
          <IonRouterOutlet>
            <Switch>
              <Route path="/tab3" render={(props: any) => <Tab3 {...{ name, setName}} />}/>
              <Route path="/" render={() => <Redirect to="/tab1" />} exact={true} />
            </Switch>
          </IonRouterOutlet>
          <IonTabBar slot="bottom">
            <IonTabButton tab="tab3" href="/tab3">
              <IonIcon icon={send} />
              <IonLabel>Tab Three</IonLabel>
            </IonTabButton>
          </IonTabBar>
        </IonTabs>
      </IonReactRouter>
    </IonApp>
  );
}

Use same tab3 file as in OP.

Clicking the button in tab3 has no effect.

Expected Behavior

Clicking on the button on tab3 will set its text to "another".

Steps to Reproduce

  1. Run app
  2. Click button

Code Reproduction URL

https://stackblitz.com/edit/s6csesf4?file=src%2Findex.tsx

Ionic Info

Ionic v8
React 18 or 19 (neither work)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    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