Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ docs/native
versioned_docs/version-v*/native
docs/cli/commands
docs/reference/glossary.md
versioned_docs/version-v*/reference/glossary.md

static/code/stackblitz

Expand Down
19 changes: 4 additions & 15 deletions docs/react/add-to-existing.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,23 +300,16 @@ Then, create `src/pages/Home.css`:

#### 5. Set up Routing

:::important

Ionic React Router currently only supports React Router v5. You must install the following specific versions of the router packages to set up routing with Ionic React.

:::

Comment on lines -303 to -308
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed? Shouldn't it be updated to v6 since we don't support v7?

Install the router packages:

```bash
npm install @ionic/react-router react-router@5 react-router-dom@5
npm install @types/react-router-dom --save-dev
npm install @ionic/react-router react-router react-router-dom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the version removed? Shouldn't it be updated to v6 since we don't support v7?

```

Then, update `src/App.tsx` to add the routes for the Home page:

```tsx title="src/App.tsx"
import { Redirect, Route } from 'react-router-dom';
import { Route, Navigate } from 'react-router-dom';
import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react';
import { IonReactRouter } from '@ionic/react-router';
import Home from './pages/Home';
Expand All @@ -329,12 +322,8 @@ const App: React.FC = () => (
<IonApp>
<IonReactRouter>
<IonRouterOutlet>
<Route exact path="/home">
<Home />
</Route>
<Route exact path="/">
<Redirect to="/home" />
</Route>
<Route path="/home" element={<Home />} />
<Route path="/" element={<Navigate to="/home" replace />} />
</IonRouterOutlet>
</IonReactRouter>
</IonApp>
Expand Down
251 changes: 93 additions & 158 deletions docs/react/navigation.md

Large diffs are not rendered by default.

32 changes: 9 additions & 23 deletions docs/react/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Let's walk through these files to understand the app's structure.
The root of your app is defined in `App.tsx`:

```tsx title="src/App.tsx"
import { Redirect, Route } from 'react-router-dom';
import { Route, Navigate } from 'react-router-dom';
import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react';
import { IonReactRouter } from '@ionic/react-router';
import Home from './pages/Home';
Expand All @@ -91,12 +91,8 @@ const App: React.FC = () => (
<IonApp>
<IonReactRouter>
<IonRouterOutlet>
<Route exact path="/home">
<Home />
</Route>
<Route exact path="/">
<Redirect to="/home" />
</Route>
<Route path="/home" element={<Home />} />
<Route path="/" element={<Navigate to="/home" replace />} />
</IonRouterOutlet>
</IonReactRouter>
</IonApp>
Expand All @@ -113,12 +109,8 @@ Routes are defined within the `IonRouterOutlet` in `App.tsx`:

```tsx title="src/App.tsx"
<IonRouterOutlet>
<Route exact path="/home">
<Home />
</Route>
<Route exact path="/">
<Redirect to="/home" />
</Route>
<Route path="/home" element={<Home />} />
<Route path="/" element={<Navigate to="/home" replace />} />
</IonRouterOutlet>
```

Expand Down Expand Up @@ -240,15 +232,9 @@ Then, add its route in `IonRouterOutlet`:

```tsx title="src/App.tsx"
<IonRouterOutlet>
<Route exact path="/home">
<Home />
</Route>
<Route exact path="/new">
<New />
</Route>
<Route exact path="/">
<Redirect to="/home" />
</Route>
<Route path="/home" element={<Home />} />
<Route path="/new" element={<New />} />
<Route path="/" element={<Navigate to="/home" replace />} />
</IonRouterOutlet>
```

Expand All @@ -259,7 +245,7 @@ Once that is done, update the button in `Home.tsx`:
```

:::info
Navigating can also be performed programmatically using React Router's `history` prop. See the [React Navigation documentation](/docs/react/navigation.md#navigating-using-history) for more information.
Navigating can also be performed programmatically using the `useIonRouter` hook. See the [React Navigation documentation](/docs/react/navigation.md#useionrouter) for more information.
:::

## Add Icons to the New Page
Expand Down
18 changes: 5 additions & 13 deletions docs/react/your-first-app.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this here so it has a thread:

Don't we need to update the playgrounds as well or is that going to be done on a separate PR? See:

<IonRouterOutlet>
<Redirect exact path="/" to="/home" />
{/*
Use the render method to reduce the number of renders your component will have due to a route change.
Use the component prop when your component depends on the RouterComponentProps passed in automatically.
*/}
<Route path="/home" render={() => <HomePage />} exact={true} />
<Route path="/radio" render={() => <RadioPage />} exact={true} />
<Route path="/library" render={() => <LibraryPage />} exact={true} />
<Route path="/search" render={() => <SearchPage />} exact={true} />
</IonRouterOutlet>

Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default Tab2;
Next, open `src/App.tsx`. Change the label to "Photos" and the `ellipse` icon to `images` for the middle tab button.

```tsx
import { Redirect, Route } from 'react-router-dom';
import { Route, Navigate } from 'react-router-dom';
import {
IonApp,
IonIcon,
Expand All @@ -259,18 +259,10 @@ const App: React.FC = () => (
<IonReactRouter>
<IonTabs>
<IonRouterOutlet>
<Route exact path="/tab1">
<Tab1 />
</Route>
<Route exact path="/tab2">
<Tab2 />
</Route>
<Route path="/tab3">
<Tab3 />
</Route>
<Route exact path="/">
<Redirect to="/tab1" />
</Route>
<Route path="/tab1" element={<Tab1 />} />
<Route path="/tab2" element={<Tab2 />} />
<Route path="/tab3" element={<Tab3 />} />
<Route path="/" element={<Navigate to="/tab1" replace />} />
</IonRouterOutlet>
<IonTabBar slot="bottom">
<IonTabButton tab="tab1" href="/tab1">
Expand Down
198 changes: 198 additions & 0 deletions docs/updating/9-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,198 @@ npm install react@latest react-dom@latest
npm install @ionic/react@latest @ionic/react-router@latest
```

3. Update to React Router v6:

```shell
npm install react-router@6 react-router-dom@6
```

If you have `@types/react-router` or `@types/react-router-dom` installed, remove them. React Router v6 includes its own TypeScript definitions:

```shell
npm uninstall @types/react-router @types/react-router-dom
```
Comment on lines +47 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should put React Router in its own top-level section like React so it is easier to find and stands out more:

Suggested change
3. Update to React Router v6:
```shell
npm install react-router@6 react-router-dom@6
```
If you have `@types/react-router` or `@types/react-router-dom` installed, remove them. React Router v6 includes its own TypeScript definitions:
```shell
npm uninstall @types/react-router @types/react-router-dom
```
### React Router
1. Ionic 9 supports React Router 6. Update to version 6 of React Router:
```shell
npm install react-router@6 react-router-dom@6
```
2. If you have `@types/react-router` or `@types/react-router-dom` installed, remove them. React Router 6 includes its own TypeScript definitions:
```shell
npm uninstall @types/react-router @types/react-router-dom
```


#### React Router v6 Migration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### React Router v6 Migration

Remove this header and just go into the steps to update


Ionic React now requires React Router v6, which has a different API from v5. Below are the key changes you'll need to make:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ionic React now requires React Router v6, which has a different API from v5. Below are the key changes you'll need to make:
Ionic React now requires React Router v6, which has a different API from v5. Below are the key changes you'll need to make.


**Route Definition Changes**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Route Definition Changes**
#### Route Definition Changes

Let's make these all headings so they can be linked to


The `component` and `render` props have been replaced with the `element` prop, which accepts JSX:

```diff
- <Route path="/home" component={Home} exact />
+ <Route path="/home" element={<Home />} />
```

Routes can no longer render content via nested children. All route content must be passed through the `element` prop:

```diff
- <Route path="/">
- <Home />
- </Route>
+ <Route path="/" element={<Home />} />
```

**Redirect Changes**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Redirect Changes**
#### Redirect Changes


The `<Redirect>` component has been replaced with `<Navigate>`:

```diff
- import { Redirect } from 'react-router-dom';
+ import { Navigate } from 'react-router-dom';

- <Redirect to="/home" />
+ <Navigate to="/home" replace />
```

**Nested Route Paths**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Nested Route Paths**
#### Nested Route Paths


Routes that contain nested routes or child `IonRouterOutlet` components need a `/*` suffix to match sub-paths:

```diff
- <Route path="/tabs" element={<Tabs />} />
+ <Route path="/tabs/*" element={<Tabs />} />
```

**Accessing Route Parameters**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Accessing Route Parameters**
#### Accessing Route Parameters


Route parameters are now accessed via the `useParams` hook instead of props:

```diff
- import { RouteComponentProps } from 'react-router-dom';
+ import { useParams } from 'react-router-dom';

- const MyComponent: React.FC<RouteComponentProps<{ id: string }>> = ({ match }) => {
- const id = match.params.id;
+ const MyComponent: React.FC = () => {
+ const { id } = useParams<{ id: string }>();
```

**RouteComponentProps Removed**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**RouteComponentProps Removed**
#### RouteComponentProps Removed


The `RouteComponentProps` type and its `history`, `location`, and `match` props are no longer available in React Router v6. Use the equivalent hooks instead:

- `history` -> `useNavigate` (see below) or `useIonRouter`
- `match.params` -> `useParams` (covered above)
- `location` -> `useLocation`

```diff
- import { RouteComponentProps } from 'react-router-dom';
+ import { useNavigate, useLocation } from 'react-router-dom';
+ import { useIonRouter } from '@ionic/react';

- const MyComponent: React.FC<RouteComponentProps> = ({ history, location }) => {
- history.push('/path');
- history.replace('/path');
- history.goBack();
- console.log(location.pathname);
+ const MyComponent: React.FC = () => {
+ const navigate = useNavigate();
+ const router = useIonRouter();
+ const location = useLocation();
+ // In an event handler or useEffect:
+ navigate('/path');
+ navigate('/path', { replace: true });
+ router.goBack();
+ console.log(location.pathname);
```

**Exact Prop Removed**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Exact Prop Removed**
#### Exact Prop Removed


The `exact` prop is no longer needed. React Router v6 routes match exactly by default. To match sub-paths, use a `/*` suffix on the path:

```diff
- <Route path="/home" exact />
+ <Route path="/home" />
```

**Render Prop Removed**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Render Prop Removed**
#### Render Prop Removed


The `render` prop has been replaced with the `element` prop:

```diff
- <Route path="/foo" render={(props) => <Foo {...props} />} />
+ <Route path="/foo" element={<Foo />} />
```

**Programmatic Navigation**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Programmatic Navigation**
#### Programmatic Navigation


The `useHistory` hook has been replaced with `useNavigate`:

```diff
- import { useHistory } from 'react-router-dom';
+ import { useNavigate } from 'react-router-dom';
+ import { useIonRouter } from '@ionic/react';

- const history = useHistory();
+ const navigate = useNavigate();
+ const router = useIonRouter();

- history.push('/path');
+ navigate('/path');

- history.replace('/path');
+ navigate('/path', { replace: true });

- history.goBack();
+ router.goBack();
```

**Custom History Prop Removed**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Custom History Prop Removed**
#### Custom History Prop Removed


The `history` prop has been removed from `IonReactRouter`, `IonReactHashRouter`, and `IonReactMemoryRouter`. React Router v6 routers no longer accept custom `history` objects.

```diff
- import { createBrowserHistory } from 'history';
- const history = createBrowserHistory();
- <IonReactRouter history={history}>
+ <IonReactRouter>
```

For `IonReactMemoryRouter` (commonly used in tests), use `initialEntries` instead:

```diff
- import { createMemoryHistory } from 'history';
- const history = createMemoryHistory({ initialEntries: ['/start'] });
- <IonReactMemoryRouter history={history}>
+ <IonReactMemoryRouter initialEntries={['/start']}>
```

**IonRedirect Removed**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**IonRedirect Removed**
#### IonRedirect Removed


The `IonRedirect` component has been removed. Use React Router's `<Navigate>` component instead:

```diff
- import { IonRedirect } from '@ionic/react';
- <IonRedirect path="/old" to="/new" exact />
+ import { Navigate } from 'react-router-dom';
+ <Route path="/old" element={<Navigate to="/new" replace />} />
```

**Path Regex Constraints Removed**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Path Regex Constraints Removed**
#### Path Regex Constraints Removed


React Router v6 no longer supports regex constraints in path parameters (e.g., `/:tab(sessions)`). Use literal paths instead:

```diff
- <Route path="/:tab(sessions)" component={SessionsPage} />
- <Route path="/:tab(sessions)/:id" component={SessionDetail} />
+ <Route path="/sessions" element={<SessionsPage />} />
+ <Route path="/sessions/:id" element={<SessionDetail />} />
```

**IonRoute API Changes**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**IonRoute API Changes**
#### IonRoute API Changes


The `IonRoute` component follows the same API changes as React Router's `<Route>`. The `render` prop has been replaced with `element`, and the `exact` prop has been removed:

```diff
- <IonRoute path="/foo" exact render={(props) => <Foo {...props} />} />
+ <IonRoute path="/foo" element={<Foo />} />
```

For more information on migrating from React Router v5 to v6, refer to the [React Router v6 Upgrade Guide](https://reactrouter.com/6.28.0/upgrading/v5).

### Vue

1. Ionic 9 supports Vue 3.0.6+. Update to the latest version of Vue:
Expand All @@ -65,3 +257,9 @@ npm install @ionic/vue@latest @ionic/vue-router@latest
```shell
npm install @ionic/core@latest
```

## Need Help Upgrading?

Be sure to look at the [Ionic 9 Breaking Changes Guide](https://github.com/ionic-team/ionic-framework/blob/main/BREAKING.md#version-9x) for the complete list of breaking changes. This upgrade guide only covers changes that require action from developers.

If you need help upgrading, please post a thread on the [Ionic Forum](https://forum.ionicframework.com/).
Loading