Next.js Discord

Discord Forum

Path agnostic static single page app

Unanswered
Tropical Kingbird posted this in #help-forum
Open in Discord
Tropical KingbirdOP
I'm building a single page app (SPA) that is exported and served as static files (no need for the nextjs server and APIs).

I don't have control where the SPA is mounted. Can be on the root of a server, or in some nested path. So I need my SPA to load everything relative to the mount point.

I managed to set assetPrefix: "./" in the nextjs config, and that works fine. I have troubles creating <Link>s now, as far as I know nextjs uses the NEXT_PUBLIC_BASE_PATH env variable to determine the correct path. I'm aware I cannot set base path to ./.

What would be the best way to have a SPA that can work on every path?

0 Replies