Base URL

What is the Base URL? Changing the Base URL (aka Public Base Path) is about changing the "URL pathname root" of our app. For example, instead of deploying our app to https://example.org/* (base: /) we can change the Base URL and deploy it to https://example.org/some/base/url/* (base: /some/base/url/).

To change the Base URL we:

  1. Add the base config to both vite.config.js#base and createPageRenderer({ base }). Example: /examples/base-url/vite.config.js and /examples/base-url/server/server.js.

  2. Use the import.meta.env.BASE_URL value injected by Vite to construct a <Link> component that prepends the Base URL. Example: /examples/base-url/components/Link.jsx.

  3. Use import.meta.env.BASE_URL when referencing static assets living in public/. Example: /examples/base-url/renderer/_default.page.server.jsx.

Example:

We can set base to 'https://another-origin.example.org/' (for cross-origin deployments) or to './' (for embedded deployments at multiple paths).

See also: