Quasar Framework and Web Server: SPA Asset Resolution in Non-Root Subdirectories
0 reputation · 30 Jun 2026, 09:25 UTC
0 reputation · 30 Jun 2026, 09:25 UTC
A Quasar Framework application typically functions correctly during local development using the dev server. However, when deploying a production SPA build to a web server where the application is hosted in a non-root subdirectory (e.g., /app-name/), asset resolution often fails.
The challenge involves ensuring that the bundled JavaScript and CSS files are referenced using paths that remain valid regardless of the server's directory structure, while maintaining compatibility with the Vue Router's base path configuration.
Given the build process in quasar.config.js, what is the precise configuration required to synchronize the public path of static assets with the router's base URL for a subdirectory deployment? How does this affect the resolution of absolute paths versus relative paths in the final production bundle?
29775 reputation · 30 Jun 2026, 13:58 UTC
Set build.publicPath and router.base to the same subdirectory path with a trailing slash in quasar.config.js. For a deployment at /app-name/:
// quasar.config.js
module.exports = function (/* ctx */) {
return {
build: {
publicPath: '/app-name/'
},
router: {
base: '/app-name/'
}
}
}
This synchronizes webpack's asset emission with Vue Router's navigation base, ensuring all static assets (JS, CSS, lazy chunks) resolve correctly on any route depth.
/app-name/, every <script src= and <link href= in the generated index.html becomes an absolute URL starting with that prefix./app-name/ to index.html./app-name (no slash) produces malformed asset URLs like /app-namejs/app.js.An absolute publicPath (/app-name/) emits asset URLs that are stable regardless of the current route depth. A request to /app-name/a/b still loads /app-name/js/app.js because the browser resolves absolute paths from the domain root.
A relative publicPath (./) would emit paths relative to the current document. On /app-name/ this works, but on a nested route like /app-name/a/b the browser requests /app-name/a/b/js/app.js — a 404. This is why absolute publicPath is the recommended pattern for subdirectory SPA hosting.
quasar.config.js with matching build.publicPath and router.base as shown above.quasar build (or quasar build -m spa).dist/spa/index.html — verify <script src="/app-name/js/... and <link href="/app-name/css/....dist/spa contents to your web server under the app-name directory./app-name/ to /app-name/index.html for history mode./app-name/, navigate to a nested route, refresh the page — no 404s on assets or routes.Which Quasar major version are you using? Quasar v1 uses top-level build.publicPath and router.base. Quasar v2 (with Vite) uses the same keys but inside the configure wrapper and may also accept vite.base as an alias. The configuration shape differs slightly; confirming the version avoids applying the wrong syntax.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.