Rspress uses file system routing, and the file path of the page is simply mapped to the routing path, which makes the routing of the entire project very intuitive.
For example, if there is a file named foo.md
in the docs
directory, the routing path for that file will be /foo
.
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
will be routed to /foo/bar
, and foo.md
will be routed to /foo
.
The specific mapping rules are as follows:
file path | route path |
---|---|
index.md |
/ |
/foo.md |
/foo |
/foo/bar.md |
/foo/bar |
/zoo/index.md |
/zoo/ |
In conventional routing, in addition to .md(x)
files, you can also use .tsx
files as route components. By default, a component is exported in .tsx
, and this component will be automatically registered in the route. For example:
Of course, if you want to customize the layout, you can add an export to declare the layout type. For example:
For detailed meanings of each pageType
, please refer to the API documentation.
If you want to customize the routing behavior, you can use the route
field in the configuration file. For example:
We recommend that you place documentation files in the docs
directory to make your project more clear. For non-documentation content, such as custom components, util functions, etc., they can be maintained outside the docs
directory. For example: