Error: RouteComponentProps issue in App.tsx

…I am updating my app from Ionic 4 to Ionic 7 (yes it has been a while)…

Getting following error I cannot figure out:

I have following this guide to a T: Intro to Ionic React Quickstart Using Ionic CLI: React Basics (still gives me this error)

My code:


import { IonIcon, IonFabButton, IonFab, IonList, IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react';
import ExploreContainer from '../components/ExploreContainer';
import './Home.css';
import { add } from 'ionicons/icons';
import { RouteComponentProps, withRouter } from "react-router";
import { useHistory } from 'react-router';

const Home: React.FC<RouteComponentProps> = () => {
  const history = useHistory();
  return (
      <IonContent fullscreen>
        <IonHeader collapse="condense">
            <IonTitle size="large">Blank2</IonTitle>
        <ExploreContainer />
        <IonFab vertical="bottom" horizontal="end" slot="fixed">
          <IonFabButton onClick={() => history.push('/new')}>
            <IonIcon icon={add} />

export default Home;


import { Redirect, Route } from 'react-router-dom';
import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react';
import { IonReactRouter } from '@ionic/react-router';

import Home from './pages/Home';


const App: React.FC = () => (
        <Route exact path="/home">
          <Home />
        <Route exact path="/">
          <Redirect to="/home" />

export default App;

Please don’t screenshot errors. Copy-and-paste the text instead. If you screenshot an error, it won’t show up in search, so people in the future who ask the same question won’t be able to find it, and they will ask the same question.

There are a couple issues with your code.

First, in App.tsx, the tutorial you linked to renders the routes like this:

<Route path="/home" component={Home} />

You are rendering your routes like this:

<Route exact path="/home">
  <Home />

These are not the same!

With the former, react-router is rendering the route, so you will get RouteComponentProps. But with the latter, react-router is not rendering the route, so you don’t get the props. You can also use the latter method, but in that case, you need to remove the RouteComponentProps from the component definition.

Second, in Home.tsx, you have two IonContent. You only want one ion-content per page, as shown in the tutorial. Also see the docs on ion-content:

There should only be one content in a single view.