Routing #
KawaPress uses file-based routing. There is no separate route table to maintain. Each Markdown file becomes a page, and its location determines the public URL.
If you have completed Getting Started, this guide explains the routing rules used by that project.
File-Based Routing #
Given this directory structure:
.
├─ guide/
│ ├─ getting-started.md
│ └─ index.md
├─ index.md
└─ about.mdKawaPress creates these routes and static files:
Directories form the URL hierarchy, and the file name becomes the final segment. Public URLs omit both .md and .html.
Your static host must resolve a request such as /guide/getting-started to its .html file. The KawaPress preview server supports this behavior. On another platform, enable clean URLs or HTML extension fallback.
How index.md Works #
The root index.md maps to /. An index.md inside a directory removes the trailing /index segment:
index.md → /
guide/index.md → /guide
guide/setup/index.md → /guide/setupDo not create both guide.md and guide/index.md. They map to the same /guide route, so choose one structure.
A trailing slash addresses the same page: /guide/ opens /guide, and the address bar then shows /guide. Links written as /guide/ in the nav, the sidebar or Markdown work as well, and Markdown links are rendered without the slash.
Site Root and Source Directory #
The current working directory is the site root when you run kawapress dev or kawapress build. By default, KawaPress reads kawapress.config.ts and Markdown pages from this directory and writes the build to dist.
Set srcDir to keep Markdown content in a relative subdirectory:
import { nagi } from 'kawapress/nagi'
export default nagi({
srcDir: 'docs',
})The project can then use this structure:
my-site/
├─ docs/
│ ├─ guide/
│ │ └─ getting-started.md
│ └─ index.md
├─ kawapress.config.ts
└─ package.jsonsrcDir changes where KawaPress reads Markdown. It does not add a segment to public routes:
docs/index.md → /
docs/guide/getting-started.md → /guide/getting-startedThe value must be relative to the site root. Absolute srcDir paths are not supported.
Excluding Source Files #
Sometimes srcDir holds .md files that should not become standalone pages, such as shared fragments for <!--@include-->, work-in-progress notes, or package README.md files. List their glob patterns in srcExclude to keep them out of the page list:
import { nagi } from 'kawapress/nagi'
export default nagi({
srcExclude: [
'snippets/**',
'**/README.md',
'**/TODO.md',
],
})Patterns in srcExclude are relative to srcDir (and match dot-prefixed paths as well). Matched files get no route or HTML output and stay out of the search index and nagi's automatic sidebar, while still remaining readable by <!--@include-->, <<<, and Data Loaders.
Route Rewrites #
In a monorepo or multi-package repository, documentation files may live inside package directories (such as packages/pkg-a/src/intro.md) while you want cleaner public URLs (such as /pkg-a/intro). rewrites maps source files to new page paths without moving files on disk.
Object Rules #
Each key is a source path pattern relative to srcDir (keeping the .md extension), and each value is the target page path. Patterns support :param parameters and * wildcards (path-to-regexp syntax, or a regular expression when the key starts with ^). Rules are tried in order and the first match wins:
import { nagi } from 'kawapress/nagi'
export default nagi({
rewrites: {
'packages/pkg-a/src/index.md': 'pkg-a/index.md',
'packages/:pkg/src/:page*': ':pkg/:page*',
},
})With the rules above, packages/core/src/guide/start.md is rewritten to core/guide/start.md, which serves at /core/guide/start.
Function Form #
Pass a function when you need custom logic. It receives the source path relative to srcDir and returns the new path, or undefined to leave the page where it is:
import { nagi } from 'kawapress/nagi'
export default nagi({
rewrites(id) {
if (id.startsWith('packages/')) {
return id.replace(/^packages\/([^/]+)\/src\//, '$1/')
}
},
})Rewritten Page Identity #
Once a page is rewritten, its new path is its identity across the site:
- Routes and build output: the router, prerendered HTML, local search, nagi's automatic sidebar,
llms.txt,sitemap.xml, andcreateContentLoader()URLs all use the rewritten path. - Relative links: relative Markdown links inside the page (such as
[Next](./next.md)) resolve from the rewritten page path, matching the public URL hierarchy. - Dead-link reports and source tracking: dead-link reports (and
sourcePathinpageData()) still name the real file on disk so you know which file to open. - Duplicate routes fail the build: if two files end up on the same route after
rewrites, the build fails and names both source files.
Linking Between Pages #
Links to another KawaPress page may be extensionless or end in .md or .html. Both relative and site-root paths work:
[Getting Started](./getting-started)
[Getting Started](./getting-started.md)
[Getting Started](./getting-started.html)
[Getting Started](/en/guide/getting-started)
[Home](/en/index.md)KawaPress resolves relative paths from the current Markdown source file, then normalizes all three page-link forms to an extensionless public route. Extensionless links mirror the URL readers see, while .md links help editors and GitHub open the source file directly. Choose one style and use it consistently within a site.
Use a heading anchor to link within a page. For example, go to the source directory section.
KawaPress generates stable anchors for Markdown headings. The page outline in the default theme uses the same anchors.
Use a complete URL for an external page, such as the Vue website. External Markdown links open in a new tab and automatically include rel="noreferrer".
Dead Links #
KawaPress checks internal Markdown links when it builds. A page that does not exist or a heading anchor that cannot be found is listed once at the end of kawapress build, and the build fails. Readers never hit a 404 that the build could have caught.
Each line of the report looks like this:
/en/guide/getting-started.md:12 ./instal missing-pageIt reads source file, line number, the link exactly as written, and why the link is dead.
What Is Checked #
- Page links: the target route must have a Markdown file. Extensionless,
.md, and.htmlforms all resolve to the same route, and/en/guide/and/en/guide/index.mdpoint at the same page. - Anchors: the target page must contain that heading ID. The range is
h1toh6, custom{#id}anchors included, and a same-page#anchoris checked too. - Other files: a link such as
[Manual](/files/manual.pdf)must match a real file in thepublicdirectory.
What Is Not Checked #
- External links and non-site addresses such as
mailto:. KawaPress does not visit them. - Raw
<a>tags in Markdown, links inside Vue components, and links generated by themes or plugins. - Whether the link text matches the destination. The check only answers "does the target exist?".
Ignoring Links #
Some links intentionally point at a page you have not written yet, or at an address that cannot be resolved. List them in deadLinks.ignore:
import { nagi } from 'kawapress/nagi'
export default nagi({
deadLinks: {
ignore: [
'/en/guide/coming-soon', // matches the resolved target exactly
'./legacy.html', // matches the written href exactly
/^\/changelog\//, // tested against both href and target
link => link.reason === 'missing-anchor',
],
},
})A string must match the whole value; it is not a substring search. A regular expression is tested against the written href and the resolved target. A function receives the whole dead link, so it can decide by reason, source, or line.
Warnings Instead of Failures #
While migrating an old site you may have too many links to fix at once. Downgrade the check to a warning:
import { nagi } from 'kawapress/nagi'
export default nagi({
deadLinks: { level: 'warn' },
})kawapress dev always warns. It only checks page existence and same-page anchors, so unfinished content never blocks your work. Use deadLinks: false to turn the check off completely.
Deploying Under a Base Path #
A site may be served below the domain root, for example:
https://example.com/my-docs/Set base to that deployment path:
import { nagi } from 'kawapress/nagi'
export default nagi({
base: '/my-docs/',
})base must start with /. KawaPress normalizes the trailing slash and applies the same prefix to Vite assets, the client router, prerendered pages, and root-relative Markdown links.
Keep using logical routes in Markdown instead of repeating /my-docs/ throughout the content:
[Getting Started](/en/guide/getting-started)The built link points to /my-docs/en/guide/getting-started. Moving the site later requires changing only the base setting.
Initial Requests and Client Navigation #
On the initial request, KawaPress renders the matched route on the server. The browser then hydrates that HTML. Readers see complete content before client-side rendering takes over.
After hydration, the documentation router KawaPress ships with handles normal same-site links:
Initial request
→ render the current page on the server
→ hydrate in the browser
→ follow an internal link
→ the router loads and shows the target pageThe initial request and production build therefore share SSR semantics, while later navigation avoids a full-page reload. External links, downloads, links with a target, and modified clicks that open a new tab keep their native browser behavior.
When the address bar carries a query or an anchor, such as /guide/routing?from=search#links, a static host still answers with the HTML of the path alone, and browsers never send the anchor to the server. KawaPress therefore hydrates that path first and switches the router to the full URL right after: the address bar keeps what the visitor typed, no extra history entry appears, and the page still lands on the target heading. Until that switch, code that reads route.query or route.hash sees empty values; read them after hydration, for instance inside watch or onMounted, when their output has to reflect the URL.
Why a built-in router? #
Routing in a documentation site is a lookup table from a path to a page. It needs no matcher, no nested routes, no named routes and no dynamic parameters. KawaPress therefore does not pull in Vue Router: it ships a small router that covers exactly what a documentation site needs. The page table is plain data, one loader fetches a page, and the router owns the URL and the browser history.
VitePress made the same call and keeps its own lightweight router for documentation sites. The difference is that KawaPress hands that ability to themes and plugins as public API instead of keeping it internal.
What the built-in router covers:
What it does not provide: nested routes, named routes, dynamic parameters, addRoute(), getRoutes(), aliases, redirects from a guard, scrollBehavior, isReady() and resolve(). None of them is needed to serve documentation, and each one can be added when a real need shows up instead of carrying a whole general-purpose router up front.
For themes and plugins, useRoute(), useRouter(), RouterLink and RouterView keep the names and the usage they have in Vue Router wherever the two overlap, so nobody has to learn a second set of concepts.
The page table comes from the Markdown files found at build time, so a page has to be a Markdown file to be reachable directly and to be prerendered.
Not Found Pages #
When no Markdown file matches a path, the development server returns a 404 status and the default interface displays its not-found page. kawapress build also generates dist/404.html for static hosts.
dist/404.html is rendered once, for the /404 route, while static hosts answer every unknown path with it. So that the first render matches the served HTML, the client hydrates /404 first and only then switches the router to the path in the address bar, which never changes. Output that depends on the current route, such as language links and the not-found texts, therefore updates to the real path once hydration is done.
KawaPress routes come from Markdown files (with optional rewrites to change their public paths). Parameterized dynamic routes and plugin-provided virtual pages are not included. Add a Markdown file whenever the site needs another page.


Comments