import styles from './layout.module.css' export default function Loader(){ return( <div className={styles.loaderContainer}> <img src="../uploads/bg1080x1920.jpg" /> <div>Loading ...</div> </div> )
import {useState, useEffect} from "react"; import { useRouter } from "next/router"; import Loader from "../components/Loader" export default function App({ Component, pageProps }) { const router = useRouter() const [loading, setLoading] = useState(false) useEffect(() => { //<-- this useEffect will be triggered just one time at component initialization router.events.on("routeChangeStart", (url) => { console.log("Route is changing"); setLoading(true) }); router.events.on("routeChangeComplete", (url) => { console.log("Route is changed"); setLoading(false) }); }, []); return ( <> {loading && <Loader />} <Component {...pageProps} />; </> ); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)