Server-Side Rendering (SSR)
wouter-vue supports full SSR with Vite, including Static Site Generation (SSG) for pre-rendering.
Basic Setup
entry-server.js:
App.vue:
Vite Configuration
vite.config.js:
Base Path Configuration
When deploying to a subdirectory (like GitHub Pages), configure the base path:
Set base in vite.config.js:
App.vue automatically reads it:
Router handles it automatically:
- Passes
baseprop to<Router> - Router internally strips base from URLs
- All navigation works correctly
- Passes
Static Site Generation (SSG)
For pre-rendering static pages, create a prerender.js script:
Add to package.json:
Redirect Handling
<Redirect> automatically sets SSR redirects:
Router Props
| Prop | Type | Default | Description |
|---|---|---|---|
ssrPath | string? | undefined | Initial path for SSR (optional) |
ssrSearch | string? | undefined | Initial search string for SSR (optional) |
base | string? | undefined | Base path for routing (e.g., /my-app) |
Notes
- Always wrap app with
<Router>for SSR - Pass
ssrPathandssrSearchprops to<Router>from entry-server - Set
baseprop automatically fromimport.meta.env.BASE_URL - Router handles base path internally - no manual URL manipulation needed
- See full example for complete SSR setup
- This documentation site is built with wouter-vue SSR/SSG - see source code