Writing an SPA with Next? (using AppRouter) #60365
Replies: 4 comments 5 replies
-
|
When you click 'back', you mean the browser's back right? If that's the case, try implementing your own button for that. Something that keeps track of route history, so you can handle navigation manually. Otherwise, if you still want to mess with the popstate, there's this discussion |
Beta Was this translation helpful? Give feedback.
-
|
Doesn't export mode cover your needs? Or is the PWA aspect (to get offline mode I guess) the roadblock there? |
Beta Was this translation helpful? Give feedback.
-
|
SPA with Next.js App Router is currently not possible. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @tomasreimers, I wanted to ask how your offline support requirement led you to SPA instead of SSR/RSC for App Router. Have you thought about creating a non-SPA app with App Router and then pre-caching all routes upon initial load? I'm building a PWA where there will be spotty connections and offline support is needed and I am investigating this strategy. Haven't completely tested it out, but I don't see why it couldn't work. I'm planning on using the Network First caching strategy where updated content is attempted to be fetched and if no network, it serves from cache. Planning on using serwist. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm trying to write an SPA with Next (Next is great, but full offline is a hard requirement for the project and that's pushing me towards an SPA). It mostly works (I can import React Router for navigation), except when I click "back". When I click back, a popstate event occurs, and because app router doesn't recognize the state, it triggers a full refresh:
https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/app-router.tsx#L544
Is there someway to disable this behavior? Pages router had a hook for this, and I see that AppRouter would disable this behavior if I set
__NEXT_WINDOW_HISTORY_SUPPORTto false (https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/app-router.tsx#L470). Is this a stable API? Is there another way to disable this refresh on popstate?Thanks,
Tomas
Beta Was this translation helpful? Give feedback.
All reactions