Is there a way to tell middleware that a page (App Router) is visited via client-side navigation?
Answered
Rough harvester ant posted this in #help-forum

Rough harvester antOP
Context:
In middleware, we’re doing auth checks, and this is an “expensive†process that ideally should only be called during a hard page visit. So we want to skip calling this middleware when a page is visited via client-side navigation. The
In middleware, we’re doing auth checks, and this is an “expensive†process that ideally should only be called during a hard page visit. So we want to skip calling this middleware when a page is visited via client-side navigation. The
next.config.js
skipMiddlewareUrlNormalize
doesn’t seem to be doing anything on app router.3 Replies

you could check it via the headers
Answer

using
headers().get('sec-fetch-dest') === 'document'
will endure that the the code runs only happens on hard reload
Rough harvester antOP
cool, thanks I got it to work.