Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vuejs/vitepress/llms.txt
Use this file to discover all available pages before exploring further.
Routing
VitePress uses file-based routing, which means your Markdown files automatically become pages based on their location in your project. No routing configuration needed!File-Based Routing Basics
Every.md file in your source directory becomes an HTML page with the same path structure.
Simple Example
Given this file structure:Project Root vs Source Directory
Understanding these concepts is key to organizing your VitePress project.Project Root
The project root is where VitePress looks for the.vitepress directory:
Source Directory
The source directory is where your Markdown files live. By default, it’s the same as the project root, but you can customize it:.vitepress/config.js
The
srcDir option is useful for keeping your documentation separate from configuration files.Linking Between Pages
Use both absolute and relative paths in your Markdown links.Best Practices
- Recommended
- Avoid
Omit file extensions so VitePress can generate correct URLs based on your config:
Linking to Non-VitePress Pages
For pages not generated by VitePress, specify the target explicitly:Clean URLs
Remove.html extensions from your URLs for cleaner, more professional links.
How It Works
By default:example.com/path.htmlWith clean URLs:
example.com/path
Enable Clean URLs
Check server support
These platforms support clean URLs automatically:
- Netlify ✓
- GitHub Pages ✓
- Vercel (requires
cleanUrlsinvercel.json)
- Internal links are generated without
.htmlextensions - Client-side redirects from
.htmlto clean URLs - Better SEO and user experience
Manual Clean URLs
If your server doesn’t support clean URLs, use this directory structure:Route Rewrites
Customize the mapping between source files and generated URLs - perfect for monorepos and complex structures.Use Case: Monorepo Documentation
You have packages with documentation alongside source code:Static Rewrites
Define explicit mappings:.vitepress/config.js
Dynamic Rewrites with Parameters
Use route parameters to avoid repetition:.vitepress/config.js
Rewrite patterns use the
path-to-regexp package syntax.Function-Based Rewrites
Use a function for complex rewrite logic:.vitepress/config.js
Dynamic Routes
Generate multiple pages from a single template using dynamic data - perfect for API documentation, blog posts, or product catalogs.The Basics
Create a route template with parameters in square brackets:[pkg] parameter will be replaced with actual values from your paths loader.
Paths Loader File
Create a.paths.js file that exports a paths function:
packages/[pkg].paths.js
TypeScript Support
UsedefineRoutes for type safety:
packages/[pkg].paths.ts
Multiple Parameters
Use multiple parameters in your route:Generating Paths from Data
Load data from local files or remote APIs:- Local Files
- Remote API
Watching Data Files
Automatically rebuild pages when data or templates change:posts/[slug].paths.js
The
watch option accepts glob patterns relative to the .paths.js file.Accessing Parameters in Pages
Use parameters in your Markdown template:packages/[pkg].md
Rendering Raw Content
Inject content from external sources without passing it as parameters:@content marker:
Setting a Base Path
If your site is deployed to a subdirectory, configure the base path:.vitepress/config.js
Next Steps
Deploy Your Site
Learn how to build and deploy your VitePress site
Markdown Features
Explore VitePress’s powerful Markdown extensions
Asset Handling
Learn how to work with images and static files
Data Loading
Load data from local or remote sources