I want to use a multi-step form with Next JS but to do so I must add the inside the app.js file which looks like this:
import React from "react";
import ReactDOM from "react-dom";
import App from "next/app";
import Head from "next/head";
import Router from "next/router";
import { SessionProvider } from "next-auth/react";
import StepContext from "./step_context.js";
import PageChange from "components/PageChange/PageChange.js";
import "@fortawesome/fontawesome-free/css/all.min.css";
import "styles/tailwind.css";
import { BrowserRouter, Routes, Route } from "react-router-dom";
Router.events.on("routeChangeStart", (url) => {
console.log(`Loading: ${url}`);
document.body.classList.add("body-page-transition");
ReactDOM.render(
<PageChange path={url} />,
document.getElementById("page-transition")
);
});
Router.events.on("routeChangeComplete", () => {
ReactDOM.unmountComponentAtNode(document.getElementById("page-transition"));
document.body.classList.remove("body-page-transition");
});
Router.events.on("routeChangeError", () => {
ReactDOM.unmountComponentAtNode(document.getElementById("page-transition"));
document.body.classList.remove("body-page-transition");
});
export default class MyApp extends App {
componentDidMount() {
let comment = document.createComment(``);
document.insertBefore(comment, document.documentElement);
}
static async getInitialProps({ Component, router, ctx }) {
let pageProps = {};
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx);
}
return { pageProps };
}
render() {
const { Component, pageProps, session } = this.props;
const Layout = Component.layout || (({ children }) => <>{children}</>);
return (
<>
<StepContext>
<React.Fragment>
<Head>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>Futur Banking</title>
</Head>
<Layout>
<Component {...pageProps} />
</Layout>
</React.Fragment>
</StepContext>
</>
);
}
}
I have to wrap anything inside return statement with tag to use the multi-step form, but this makes the web show the multi-step page form on every url.
If i change the code and put it inside the component it shows the form added below every page.
How can I fix this issue and show the multi-step form only inside the specific url not on every page.