Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load splash screen before nextjs

I have a NextJS website and I want to add a Splash Screen for before website is loaded

but because the Splash Screen is also in the NextJS code, it will loading when nextjs rendered on the server and the JS downloaded and executed on the client. in fact, it's useless because it will execute after the page is ready!

how can I do the Splash Screen before react completely loaded and executed ?

I also use nginx for proxy_pass

like image 790
samir Avatar asked Sep 10 '25 01:09

samir


2 Answers

You can easy use loading.js file in your folder,see documentation - https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming

like image 92
AleshaLearner Avatar answered Sep 12 '25 13:09

AleshaLearner


use this code

useEffect(() => {
        const handleStart = () => { setPageLoading(true); };
        const handleComplete = () => {
                 setPageLoading(false);
        };
        router.events.on('routeChangeStart', handleStart);
        router.events.on('routeChangeComplete', handleComplete);
        router.events.on('routeChangeError', handleComplete);
    }, [router]);

and use pageLoding for show splash

like image 41
Seyed Kazem Mousavi Avatar answered Sep 12 '25 15:09

Seyed Kazem Mousavi