htmlreactjsionic-react

How to create a new page on Ionic with react?


I run command ionic generate pages/login but me return this error

Since you're using the React project type, this command won't work. The Ionic CLI doesn't know how to generate framework components for React


Solution

  • You'll have to make a new file in e.g src/pages/ (e.g. with the name xy.tsx) with the following contents:

    import React from "react";
    import {IonPage} from "@ionic/react";
    const PageXY: React.FC = () => {
        return (
            <IonPage>
                ...
            </IonPage>
        );
    };
    
    export default PageXY;
    

    and in your App.tsx aka Router you have to import it with import PageXY from "./pages/xy"; and hook it up to the Router like so: <Route path="/xy" component={PageXY} exact />

    Hope this still helps someone