You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{useEffect,useRef}from'react';importcnfrom'classnames';import{gsap}from'gsap/dist/gsap';importSingletonRouter,{Router}from'next/router';importstylesfrom'./PageLoader.module.scss';constPageLoader=()=>{const$loader=useRef<HTMLDivElement>();useEffect(()=>{// @ts-ignoreif(!SingletonRouter.router?.change){return;}// @ts-ignoreconstoriginalChangeFunction=SingletonRouter.router.change;constoriginalOnBeforeUnloadFunction=window.onbeforeunload;// @ts-ignoreSingletonRouter.router.change=async(...args)=>{// get variables from the argsconst[,,as,options]=args;// check if shallow routingconstisShallow=!!options?.shallow;// check if you are on the same URLconstchangedUrl=as.split('?')[0];constsameURL=SingletonRouter.router.pathname===changedUrl;if((sameURL&&isShallow)||(sameURL&&!isShallow)){// @ts-ignoreRouter.prototype.change.apply(SingletonRouter.router,args);}else{gsap.to($loader?.current,{duration: 0.3,autoAlpha: 1,onComplete: ()=>{// @ts-ignoreRouter.prototype.change.apply(SingletonRouter.router,args);},});}};consthandleRouteChangeComplete=()=>{gsap.to($loader?.current,{duration: 0.3,autoAlpha: 0,});};SingletonRouter.router.events.on('routeChangeComplete',handleRouteChangeComplete);/* * When the component is unmounted, the original change function is assigned back. */return()=>{// @ts-ignoreSingletonRouter.router.change=originalChangeFunction;window.onbeforeunload=originalOnBeforeUnloadFunction;SingletonRouter.router.events.off('routeChangeComplete',handleRouteChangeComplete);};},[$loader]);return<divref={$loader}className={cn(styles.wrapper,'js-loader')}/>;};exportdefaultPageLoader;
The text was updated successfully, but these errors were encountered:
PageLoader.tsx
The text was updated successfully, but these errors were encountered: