Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router.push() progress bar #45499

Closed
rossanodr opened this issue Feb 1, 2023 · 5 comments
Closed

router.push() progress bar #45499

rossanodr opened this issue Feb 1, 2023 · 5 comments

Comments

@rossanodr
Copy link

Describe the feature you'd like to request

A progress bar which shows the progress while loading a new page.
It's a little strange to use useRouter and have no indication that the new page is going to load.

Describe the solution you'd like

Something like https://www.npmjs.com/package/nextjs-progressbar
It was great.

Describe alternatives you've considered

Currently in next Js 13 unfortunately I've found no alternatives

@guitheengineer
Copy link
Contributor

You can play an animation on the routeChangeStart' event and end it on the routeChangeEnd event

  const router = useRouter()
  useEffect(() => {
    router.events.on('routeChangeStart', routeChangeStart);
    router.events.on('routeChangeComplete', routeChangeEnd);
    router.events.on('routeChangeError', routeChangeError);
    return () => {
      router.events.off('routeChangeStart', routeChangeStart);
      router.events.off('routeChangeComplete', routeChangeEnd);
      router.events.off('routeChangeError', routeChangeError);
    };
  }, []);

This is how this library is doing actually: https://github.com/apal21/nextjs-progressbar/blob/master/src/index.tsx

Do you think something else is needed or you can just use the router events?

@rossanodr
Copy link
Author

You can play an animation on the routeChangeStart' event and end it on the routeChangeEnd event

  const router = useRouter()
  useEffect(() => {
    router.events.on('routeChangeStart', routeChangeStart);
    router.events.on('routeChangeComplete', routeChangeEnd);
    router.events.on('routeChangeError', routeChangeError);
    return () => {
      router.events.off('routeChangeStart', routeChangeStart);
      router.events.off('routeChangeComplete', routeChangeEnd);
      router.events.off('routeChangeError', routeChangeError);
    };
  }, []);

This is how this library is doing actually: https://github.com/apal21/nextjs-progressbar/blob/master/src/index.tsx

Do you think something else is needed or you can just use the router events?

It does not work with next13.
the useRouter from "next/navigation" does not have events :/
and the next/router can't be used with the app folder

@SamRoehrich
Copy link

I am curious if there is a way to use Suspense to achieve this. Not sure what the requirements are for your use case but I could see if you had 3 requests for example, updating the progress of a loader component as each request comes back.

@JavierLopezSCG
Copy link

JavierLopezSCG commented Feb 25, 2023

Bumping the issue.

The new useRouter from Next 13 'next/navigation' (AppRouterInstance) doesn't expose any properties to detect the events on routes. Any possible solution?

@guitheengineer
Copy link
Contributor

I think they'll eventually add these events again, just a matter of time.

One PR is open to listen to routeChangeStart:
#46391

@vercel vercel locked and limited conversation to collaborators Feb 27, 2023
@timneutkens timneutkens converted this issue into discussion #46478 Feb 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants