Link does not automatically prefetch pages for routes with "has" rewrites
See original GitHub issueWhat version of Next.js are you using?
12.0.4
What version of Node.js are you using?
14x
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
A visible Link
will automatically prefetch page json for static pages (along with the chunk) when visible. However, if a rewrite is used to add something like a country code to the route, then the Link will no longer prefetch.
Expected Behavior
Links can prefetch routes with or without a rewrite.
To Reproduce
I’ve created a minimal case here: https://github.com/ericmatthys/nextjs-prefetch-with-rewrite It is deployed here: https://nextjs-prefetch-with-rewrite.vercel.app/
If you look at network requests as you browse through the two different paths, you’ll see the “Without Rewrite” path is able to prefetch and navigate through the path quicker. The “With Rewrite” path does not prefetch.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Unable to prefetch pages built from dynamic routes #10449
When accessing my pages generated from a dynamic URL, it is trying to prefetch .js files based off of their slugs (and 404'ing)...
Read more >Route prefetching in Next.js - web.dev
Normally, a page is downloaded when you follow a link to it, but Next.js automatically prefetches the JavaScript needed to render the page....
Read more >Dealing with links in Next.js - LogRocket Blog
In Next 9, automatic prefetching was turned on by default. This prefetches link contents when they are in the page's viewport. Next uses...
Read more >next/link | Next.js
In order for the <Link /> component to properly prefetch links with rewrites via Middleware, you need to tell Next.js both the URL...
Read more >Microsoft Edge Browser Policy Documentation
HomepageLocation, Configure the home page URL ... ForceSync, Force synchronization of browser data and do not show the sync consent prompt.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This appears to be due to the
rewrite
usinghas
when on Vercel but not locally so might be a potential duplicate of https://github.com/vercel/next.js/issues/24798It’s best to use middleware for this sort of rewrite now, which avoids the issue.