Ionic React Router

Installation

Import

Sub Tags

Example 1

<IonReactRouter>
  <IonRouterOutlet>
    <Route path="/home" component={Home} exact={true} />
    <Route exact path="/" render={() => <Redirect to="/home" />} />
  </IonRouterOutlet>
</IonReactRouter>

Example 2

<IonReactRouter>
  <IonRouterOutlet>
    <Route exact path="/home">
      <Home />
    </Route>
    <Route exact path="/">
      <Redirect to="/home" />
    </Route>
  </IonRouterOutlet>
</IonReactRouter>

Example 3

<IonReactRouter>
  <IonSplitPane contentId="main">
    <Menu />
    <IonRouterOutlet id="main">
      {/* <Route exact path={match.url} component={UsersListPage} /> */}
      {/* <Route path={`${match.url}/users/:id`} component={UserDetailPage} /> */}
      {/* <Route render={() => <Redirect to={match.url} />} /> */}
      <Switch>
        <Route path="/about" exact={true}>
          <AboutPage />
        </Route>
        <Route path="/" exact={true}>
          <HomePage />
        </Route>
        <Route path="*">
          <NotFoundPage />
        </Route>
      </Switch>
    </IonRouterOutlet>
  </IonSplitPane>
</IonReactRouter>

Example 5 - Nested

<Routes>
  <Route path="/" element={<App />}>
    <Route index element={<Home />} />
    <Route path="teams" element={<Teams />}>
      <Route path=":teamId" element={<Team />} />
      <Route path="new" element={<NewTeamForm />} />
      <Route index element={<LeagueStandings />} />
    </Route>
  </Route>
</Routes>