I really want to show top-bar-ish animation in my web when client is requesting a new page by clicking a link or programatically router.push
or router.replace
, but Next.js dev decided to remove the router events in Next.js 13.
So, i ended up by listening to the document click event. It's inspired by nextjs-toploader, but it only works for next/link
component, not programmatically like router.push
and router.replace
Better than nothing. I created a my own react context for the top-bar loader, and also have functions to programatically start and stop
The idea of the document click event is listening to the document click and detect if the anchor element (next/link
component) has been clicked.
'use client'