THE GITHTML FIELD GUIDE

Check VitePress base paths before serving docs in a subdirectory

Set VitePress's base path to match the subdirectory where the site will be served, then test a production build at that path. Inspect generated links and assets rather than fixing only the homepage. A base-path setting describes a serving arrangement; it does not make a multi-file site automatically portable when individual HTML files are moved elsewhere.

Write the intended URL before editing configuration

Start with a concrete destination such as an example site's handbook subdirectory. Identify the site root, documentation root, and any route prefix added by the host. A mismatch can leave the homepage visible while styles, scripts, or nested links request the wrong location. Inspect existing configuration and environment-specific overrides before adding another base value. Do not infer the production path from a development server running at the root. If the actual hosting arrangement is undecided, record that uncertainty instead of guessing a prefix that becomes embedded throughout the generated artifact.

Test representative paths under the chosen prefix

The sample configuration uses a fictional handbook prefix. Build with the project's installed version and serve the output through a local arrangement that reproduces the intended path. Visit the root page and at least one nested page directly, then follow internal links between them. Inspect asset requests and generated references when something fails. Separate a wrong base prefix from a missing output file or an absolute URL hard-coded in source. Changing the base will not necessarily repair every manually authored resource reference. Keep a small fixture page with an image, a code block, and an internal link to expose these differences.

ts
import { defineConfig } from 'vitepress';

export default defineConfig({
  base: '/handbook/',
});

Review redirects and portable-copy expectations separately

Confirm that the site's entry URL and trailing-slash behavior align with the host's actual routing. Do not add redirects or rewrite rules without understanding the deployment system and having authority to change it. This guide's local check establishes the artifact's path assumptions, not the final host's behavior. If someone needs one document for reading outside the site, create and verify that export separately rather than changing the whole site's base to suit a file viewer. Record the tested prefix and build configuration with the artifact. That context helps future reviewers distinguish a routing regression from an attempt to use the site under a different serving model. Keep screenshots of the observed failure alongside the requested resource path when reporting a bug. Visual symptoms alone rarely reveal whether the missing prefix affects an asset, navigation target, or host rewrite.

  1. Write the intended public path and inspect all existing base-related overrides.
  2. Build and test at the actual subpath rather than only at the local root.
  3. Check nested direct navigation, internal links, and representative assets.
  4. Treat a portable document export as a separate requirement from website routing.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All documentation builds and formats guides →

Read as MarkdownAll guides

Check VitePress base paths before serving docs in a subdirectory · gitHtml