Next.js next/link doesn't trigger middleware

I have a next.js 13.4.9 website using the app router. I’m using middleware for internationalization. And I’m using SSG with ISR.
Everything works except one thing. If I navigate with the Url, middleware is executed as expected. But when navigating through next/link, middleware is not executed. I know this because I’m cheking the edge function logs. How can I fix it?

The website url is:

One way to check that the middleware works is the following. If you access this url:
the url will be rewritten to

To check that navigating through next/link won’t trigger middleware you can click on the “català” button in the header, and you’ll be brought to This time, though, the url won’t be rewritten and it will stay as is.

I’ve realized that the problem only occurs when I’m doing SSG and ISR, without these, next/link works as expected.

Thanks for posting. I think I’ve narrowed down the issue to the rsc: 1 request header that’s being passed to the prefetch URLs next/link is generating. When we get the rsc header, we route that request through the rsc Edge Function that Next Runtime generates. I’m not sure if the Middleware is called after that Edge Function or not. I’ll confirm that with the devs and let you know.

Please leave the site on so we can continue testing.

1 Like

I have this same problem but with the getServerSideProps. It’s not triggering thru the usage of next/link. But when accessing directly works.

Let me know if I can be useful for this issue.

If you can share your repo, that would be good. If not, this will still be investigated, but right now, this is not on the highest priority.

Are there an updates on this?

None so far, and to set expectations, it would take much longer to get this to a resolution.