Replies: 3 comments 2 replies
-
I file an issue to add an enhacement on |
Beta Was this translation helpful? Give feedback.
2 replies
-
Check the comment on the issue, there is a repo with the solution: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is an analysis of #159, but for dynamic routes; the problem here is that we need to handle it from client (service worker) and server side:
index.html
when something missing is requested, in our case, for any pathhi/:name
, the server will return the content ofindex.html
and so the flashing appears.index.html
even when the server can serve the content of the dynamic page.Following I will describe a prove of concept that works, but we need to manually configure the app. I have push here https://github.com/userquin/vitesse/tree/chore/fix-missing-routes-on-sw the working project, to run it once cloned on local machine, from the root folder:
pnpm run build && pnpm run serve
Open
https://localhost
and try F5 onhi
route.Step one, include dynamic routes generation:
nuxtStyle
onvite-plugin-pages
configurationextendRoute
tovite-plugin-pages
configuration to just skip only_.vue
: the configuration for previous and this step will be:includedRoutes
tossgOptions
forvite-ssg
:_
instead: rename[...all].vue
andhi/[name].vue
pages to_.vue
andhi/_name.vue
respectivellyStep 2, configure server to serve dinamyc routes:
I've included a modified version for
https-localhost
using expressstatic
withfallthrough
enabled, that is, when missing resource, the middleware will just callnext
in the chain and then we intercept the request:At this point, we are able to serve dynamic routes content from server (there is no SSR at all, the client will just change the title once
hi/_name.html
with all its assets loaded).But the service worker will still serve the
index.html
. If you make a hard refresh the flash dissapear, while using just F5 you will see the flashing.Step 3, configure the service worker to serve dynamic routes content.
The problem is that we cannot use
generateSW
since there is no way to change the default routing, that is, all request that doesn't do an exact match will fallback toindex.html
, just open the service worker onnetlify
and you will find this entry at bottom ofsw.js
file:To solve the problem, I have included a custom service worker to build a new one with the changes:
and also update the
PWAPlugin
configuration with:Beta Was this translation helpful? Give feedback.
All reactions