|
import { useRouter } from 'next/router' |
|
import NProgress from 'nprogress' |
|
import { useEffect } from 'react' |
|
|
|
|
|
|
|
|
|
export default function LoadingProgress() { |
|
const router = useRouter() |
|
|
|
useEffect(() => { |
|
const handleStart = (url) => { |
|
NProgress.start() |
|
} |
|
|
|
const handleStop = () => { |
|
NProgress.done() |
|
} |
|
|
|
router.events.on('routeChangeStart', handleStart) |
|
router.events.on('routeChangeError', handleStop) |
|
router.events.on('routeChangeComplete', handleStop) |
|
return () => { |
|
router.events.off('routeChangeStart', handleStart) |
|
router.events.off('routeChangeComplete', handleStop) |
|
router.events.off('routeChangeError', handleStop) |
|
} |
|
}, [router]) |
|
} |
|
|