Next.js Discord

Discord Forum

Cancelling route activation in Next (using pages directory)

Unanswered
Siberian posted this in #help-forum
Open in Discord
SiberianOP
Hi, what is a good way to cancel a route activation based on given criteria? I currently use the router.events.on('routeChangeStarted') handler approach, but when I redirect in there it logs an error to the console:

Error: Abort fetching component for route: "/test"
    at handleCancelled (router.js:408:27)
    at Router.getRouteInfo (router.js:1143:13)
    at async Router.change (router.js:778:29)


I understand this is normal and expected, but I'd like to hide it, since redirection would be manually triggered and therefore not an error. Is there a way to do that, or is there a better approach?

0 Replies