nuxt: Extremely weird routing bug(s)
It seems that in various scenarios, the app inconsistently redirects to /
.
I first encountered this behaviour when trying to directly access a non-existing route (i.e. https://vitesse-nuxt3.netlify.app/non-existing-route) and then hit refresh. Sometimes it happens after the first refresh, but usually after at most four refreshes, the redirect occurs.
This also happens consistently when using NuxtLink
with href="/some-route"
and target="_blank"
. Instead of loading the catch all route, the app redirects to /
.
After further testing, it seems to happen on existing routes too (i.e. https://vitesse-nuxt3.netlify.app/hi/antfu). Same behaviour, after 1-4 refreshes, it redirects to /
.
Furthermore, when using SSG and linking static files (i.e. PDFs in my case), they never load when clicking the NuxtLink
, but redirect to /
. They can be accessed directly, but after loading the app, this stops working too.
My current workaround is to disable pwa
alltogether, so any suggestions are appreciated!
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 19 (10 by maintainers)
@userquin got a chance to test your suggestions and they worked, thanks again!
You dont need to include a custom sw , generateSW will generate similar code in elk, any resource not in the sw precache manifest should be excluded from sw nav controller (denylist) and optionallly included in a custom runtime caching if required
Check the service worker in the elk.zone repo (service-worker/sw.ts), check the denylist entries
About pdf files, if you dont add them to the sw precaching (globPattern) you need to add .pdf files to the denylist (
/\.pdf$/
), otherwise you will get home page response@bogdanciuca yes, it is about dynamic pages: should be excluded with denylist and runtime caching entry, the current PR is too complex to be solved programatically, ppl can have distinct caching strategies and options (per route, per routes group…). My suggestion, include custom runtime caching for those routes.
NOTE bout the draft PR: I need to do some research, but it won’t be merged anytime soon (or maybe ever)
check https://github.com/antfu/vitesse-nuxt3/pull/98 and https://github.com/vite-pwa/nuxt/pull/66
EDIT: some explanations here with SvelteKit (same problem with same solution): https://github.com/vite-pwa/sveltekit/issues/65#issuecomment-1734213190