@@ -10,19 +10,24 @@ order: 2
10
10
Routes are configured in ` app/routes.ts ` . The Vite plugin uses this file to create bundles for each route.
11
11
12
12
``` ts filename=app/routes.ts
13
- import { route } from " react-router/config" ;
14
-
15
- export default [
16
- route .index (" ./home.tsx" ),
13
+ import {
14
+ type RoutesConfig ,
15
+ route ,
16
+ index ,
17
+ layout ,
18
+ } from " @react-router/dev/routes" ;
19
+
20
+ export const routes: RoutesConfig = [
21
+ index (" ./home.tsx" ),
17
22
route (" about" , " ./about.tsx" ),
18
23
19
- route . layout (" ./auth/layout.tsx" , [
24
+ layout (" ./auth/layout.tsx" , [
20
25
route (" login" , " ./auth/login.tsx" ),
21
26
route (" register" , " ./auth/register.tsx" ),
22
27
]),
23
28
24
29
route (" concerts" , [
25
- route . index (" ./concerts/home.tsx" ),
30
+ index (" ./concerts/home.tsx" ),
26
31
route (" :city" , " ./concerts/city.tsx" ),
27
32
route (" trending" , " ./concerts/trending.tsx" ),
28
33
]),
@@ -31,19 +36,29 @@ export default [
31
36
32
37
## File System Routes
33
38
34
- If you prefer a file system routing convention there are two conventions from React Router , but you can also make your own.
39
+ If you prefer a file system routing convention, you can use the convention provided with Remix v2 , but you can also make your own.
35
40
36
41
``` tsx filename=app/routes.ts
37
- import { nested , flat } from " @react-router/fs-routes" ;
42
+ import { type RoutesConfig } from " @react-router/dev/routes" ;
43
+ import { remixRoutes } from " @react-router/remix-v2-routes" ;
44
+
45
+ export const routes: RoutesConfig = remixRoutes ();
46
+ ```
38
47
39
- export const routes = [
40
- // simulates Next.js route file names
41
- ... nested (" ./routes" ),
48
+ You can also mix routing conventions into a single array of routes.
49
+
50
+ ``` tsx filename=app/routes.ts
51
+ import {
52
+ type RoutesConfig ,
53
+ route ,
54
+ } from " @react-router/dev/routes" ;
55
+ import { remixRoutes } from " @react-router/remix-v2-routes" ;
42
56
43
- // simulates Remix v2 route file names
44
- ... flat (" ./routes" ),
57
+ export const routes: RoutesConfig = [
58
+ // Provide Remix v2 file system routes
59
+ ... (await remixRoutes ()),
45
60
46
- // can still do regular configuration
61
+ // Then provide additional config routes
47
62
route (" /can/still/add/more" , " ./more.tsx" ),
48
63
];
49
64
```
@@ -76,10 +91,18 @@ function Header() {
76
91
Routes can be nested inside parent routes. Nested routes are rendered into their parent's [ Outlet] [ outlet ]
77
92
78
93
``` ts filename=app/routes.ts
79
- route (" dashboard" , " ./dashboard.tsx" , () => [
80
- route .index (" ./home.tsx" ),
81
- route (" settings" , " ./settings.tsx" ),
82
- ]);
94
+ import {
95
+ type RoutesConfig ,
96
+ route ,
97
+ index ,
98
+ } from " @react-router/dev/routes" ;
99
+
100
+ export const routes: RoutesConfig = [
101
+ route (" dashboard" , " ./dashboard.tsx" , [
102
+ index (" ./home.tsx" ),
103
+ route (" settings" , " ./settings.tsx" ),
104
+ ]),
105
+ ];
83
106
```
84
107
85
108
``` tsx filename=app/dashboard.tsx
@@ -100,41 +123,52 @@ export default defineRoute$({
100
123
101
124
## Layout Routes
102
125
103
- Using ` route.layout ` , layout routes create new nesting for their children, but they don't add any segments to the URL. They can be added at any level.
126
+ Using ` layout ` , layout routes create new nesting for their children, but they don't add any segments to the URL. They can be added at any level.
127
+
128
+ ``` tsx filename=app/routes.ts lines=[9,15]
129
+ import {
130
+ type RoutesConfig ,
131
+ route ,
132
+ layout ,
133
+ index ,
134
+ } from " @react-router/dev/routes" ;
104
135
105
- ``` tsx filename=app/routes.ts lines=[3,9]
106
- import { route } from " react-router/config" ;
107
- export const routes = [
108
- route .layout (" ./marketing/layout.tsx" , [
109
- route .index (" ./marketing/home.tsx" ),
136
+ export const routes: RoutesConfig = [
137
+ layout (" ./marketing/layout.tsx" , [
138
+ index (" ./marketing/home.tsx" ),
110
139
route (" contact" , " ./marketing/contact.tsx" ),
111
140
]),
112
141
route (" projects" , [
113
- route . index (" ./projects/home.tsx" ),
114
- route . layout (" ./projects/project-layout.tsx" , [
142
+ index (" ./projects/home.tsx" ),
143
+ layout (" ./projects/project-layout.tsx" , [
115
144
route (" :pid" , " ./projects/project.tsx" ),
116
145
route (" :pid/edit" , " ./projects/edit-project.tsx" ),
117
146
]),
118
147
]),
119
- ]) ;
148
+ ];
120
149
```
121
150
122
151
## Index Routes
123
152
124
153
``` ts
125
- route . index (componentFile );
154
+ index (componentFile );
126
155
```
127
156
128
157
Index routes render into their parent's [ Outlet] [ outlet ] at their parent's URL (like a default child route).
129
158
130
159
``` ts filename=app/routes.ts
131
- import { route } from " react-router/config" ;
132
- export default [
160
+ import {
161
+ type RoutesConfig ,
162
+ route ,
163
+ index ,
164
+ } from " @react-router/dev/routes" ;
165
+
166
+ export const routes: RoutesConfig = [
133
167
// renders into the root.tsx Outlet at /
134
- route . index (" ./home.tsx" ),
135
- route (" dashboard" , " ./dashboard.tsx" , () => [
168
+ index (" ./home.tsx" ),
169
+ route (" dashboard" , " ./dashboard.tsx" , [
136
170
// renders into the dashboard.tsx Outlet at /dashboard
137
- route . index (" ./dashboard-home.tsx" ),
171
+ index (" ./dashboard-home.tsx" ),
138
172
route (" settings" , " ./dashboard-settings.tsx" ),
139
173
]),
140
174
];
@@ -222,25 +256,6 @@ You can destructure the `*`, you just have to assign it a new name. A common nam
222
256
const { " *" : splat } = params ;
223
257
```
224
258
225
- ## Case Sensitive Routes
226
-
227
- You can make your routes case sensitive by exporting a ` config ` object from ` app/routes.ts ` :
228
-
229
- ``` ts filename=app/routes.ts
230
- import { route } from " react-router/config" ;
231
-
232
- export const config = {
233
- caseSensitive: true ,
234
- };
235
-
236
- export default [
237
- route (" wEll-aCtuAlly" , " ./well-actually.tsx" ),
238
- ];
239
- ```
240
-
241
- - Will match ` "wEll-aCtuAlly" `
242
- - Will not match ` "well-actually" `
243
-
244
259
## Component Routes
245
260
246
261
You can also use components that match the URL to elements anywhere in the component tree:
0 commit comments