Skip to content

Commit 76a5680

Browse files
committed
docs: update README.md
1 parent abf367d commit 76a5680

1 file changed

Lines changed: 90 additions & 3 deletions

File tree

README.md

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,96 @@
22

33
<h1 align='center'>vite-plugin-remix-router</h1>
44

5-
<p align='center'>Remix routing for React and Vite</p>
5+
<p align='center'>Remix style file-system routing for React and Vite</p>
66

77
<br/>
88

9-
> **Disclaimer**: vite-plugin-remix-router is still in development and not
10-
> stable yet. It's not recommended to use it in production.
9+
## Introduction
10+
11+
The `vite-plugin-remix-router` is a Vite plugin that helps you add
12+
[ Remix ](https://remix.run/) style file-system routing to your
13+
[ Vite ](https://vitejs.dev/) React project.
14+
15+
## Getting Started
16+
17+
First, install the plugin in your Vite project:
18+
19+
```bash
20+
npm i --D vite-plugin-remix-router
21+
22+
yarn add --dev vite-plugin-remix-router
23+
24+
pnpm add --D vite-plugin-remix-router
25+
```
26+
27+
Then, import it into your `vite.config.ts`. You can pass it configuration
28+
options as well.
29+
30+
```typescript
31+
import { defineConfig } from 'vite'
32+
import react from '@vitejs/plugin-react'
33+
import RemixRouter from 'vite-plugin-remix-router'
34+
35+
export default defineConfig({
36+
plugins: [
37+
react(),
38+
RemixRouter({
39+
routesDirectory: 'src/routes',
40+
extensions: ['tsx', 'jsx'],
41+
}),
42+
],
43+
})
44+
```
45+
46+
Now you can use `virtual:routes` to import generated routes object:
47+
48+
```typescript
49+
import { useRoutes } from 'react-router-dom'
50+
import { routes } from 'virtual:routes'
51+
52+
export function Routes() {
53+
return useRoutes(routes)
54+
}
55+
```
56+
57+
## Defining Routes
58+
59+
To define a new route, simply create a new file in the routes directory. The
60+
default export must be a react component that will be used as a route component.
61+
As the name implies, the plugin supports
62+
[ Remix routing convention ](https://remix.run/docs/en/v1/api/conventions#route-file-conventions)
63+
for naming route files. You can learn more in
64+
[ Remix routing documentation ](https://remix.run/docs/en/v1/guides/routing).
65+
66+
```
67+
app
68+
├── root.jsx
69+
└── routes
70+
├── sales 👈 Layout route
71+
│ │ ├── invoices
72+
│ │ │ └── $invoiceId.jsx 👈 Dynamic route
73+
│ │ └── invoices.jsx
74+
│ └── sales.jsx
75+
├── __auth 👈 Pathless layout route
76+
│ ├── login.jsx
77+
│ ├── logout.jsx
78+
│ └── signup.jsx
79+
├── __auth.jsx
80+
└── $.jsx 👈 Splat route
81+
```
82+
83+
> Please note that
84+
> [ Remix route module APIs ](https://remix.run/docs/en/v1/api/conventions#route-module-api)
85+
> like `action`, `loader`, etc. are not supported yet and will be added in
86+
> future releases.
87+
88+
## Acknowledgement
89+
90+
Thanks to [ Remix ](https://remix.run/) for routing conventions and
91+
[ vite-plugin-pages ](https://github.com/hannoeru/vite-plugin-pages) and
92+
[ vite-plugin-next-react-router ](https://github.com/zoubingwu/vite-plugin-next-react-router)
93+
for inspiration.
94+
95+
## License
96+
97+
Distributed under the [MIT license](/LICENSE.md).

0 commit comments

Comments
 (0)