I just pulled in react-topbar-progress-indicator from NPM and connected it to the same routing events, works equally well and the user is not left waiting with nothing happening
import React, { useEffect, useState } from 'react'; import { Router } from 'next/router'; import TopBarProgress from 'react-topbar-progress-indicator'; TopBarProgress.config({ barColors: ['rgba(255,0,0,.75)'], shadowBlur: 5, barThickness: 2, }); const ProgressIndicator: React.FC = () => { const [visible, setVisible] = useState(false); useEffect(() => { const start = () => void setVisible(true); const complete = () => void setVisible(false); Router.events.on('routeChangeStart', start); Router.events.on('routeChangeComplete', complete); Router.events.on('routeChangeError', complete); return () => { Router.events.off('routeChangeStart', start); Router.events.off('routeChangeComplete', complete); Router.events.off('routeChangeError', complete); }; }, []); return <>{visible && <TopBarProgress />}</>; }; export default ProgressIndicator;
Thank for it. useRoutes().events Doesn't work for me.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I just pulled in react-topbar-progress-indicator from NPM and connected it to the same routing events, works equally well and the user is not left waiting with nothing happening
Thank for it. useRoutes().events Doesn't work for me.