Conventional route
What is it?
Rspress uses file system routing: each page file path maps directly to a route path, making project routes easy to understand.
For example, a file named foo.md in the docs directory is routed to /foo.
Mapping rules
Rspress automatically scans the root directory and all subdirectories, and maps file paths to route paths. For example, if you have the following file structure:
Then bar.md is routed to /foo/bar, and /foo/index.md is routed to /foo/.
The specific mapping rules are as follows:
Do not create files and folders with the same name, because they cause routing conflicts. For example, the following file structure is not allowed:
TSX routing
In conventional routing, .tsx files can also act as route components in addition to .md(x) files. By default, the component exported from a .tsx file is automatically registered as a route. For example:
To customize the layout, export frontmatter and declare the layout type:
For the meaning of each pageType, see the API documentation.
Custom behavior
If you want to customize the routing behavior, you can use the route field in the configuration file. For example:
Exclude files starting with _ by default
In the docs directory, MDX fragments or React components must be excluded from routing with route.exclude. For convenience, files starting with "_" are excluded by default through route.excludeConvention.
You can also place components in adjacent directories outside the docs directory. For example:
It is rendered as:
button
This is text from MDX
Best practices
We recommend placing documentation files in the docs directory to keep the project structure clear. Keep non-documentation content, such as custom components and utility functions, outside docs when possible. If they must live in docs, exclude them with route.exclude.
If you place custom components or document fragments in the docs directory, use route.exclude; otherwise, those files are automatically registered as routes and may cause unexpected behavior.
Here is a best practice file structure that includes MDX fragments and React components, custom themes, conventional routing, and internationalization: