You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CLI supports two approaches for routing: **file-system based routing** (recommended, Next.js-style) and manual React Router setup.
161
161
162
-
### Approach 1: File-System Based Routing (Recommended)
162
+
### Approach 1: File-System Based Routing (Recommended) ✅
163
163
164
-
Organize your schema files in a `pages/` directory structure, and the CLI will automatically generate routes based on the folder hierarchy.
164
+
The CLI automatically detects a `pages/` directory and generates routes based on the folder hierarchy.
165
165
166
166
#### Directory Structure
167
167
@@ -177,7 +177,7 @@ my-app/
177
177
│ │ └── [id].schema.json → /blog/:id
178
178
│ └── users/
179
179
│ └── [userId].schema.json → /users/:userId
180
-
└── app.schema.json (optionallayout)
180
+
└── app.schema.json (optional, reserved for future layout support)
181
181
```
182
182
183
183
#### Example Page Schemas
@@ -244,6 +244,17 @@ The serve command will:
244
244
3. Generate route configuration based on file structure
245
245
4. Set up the application with all routes
246
246
247
+
You'll see output like:
248
+
```
249
+
📁 Detected pages/ directory - using file-system routing
250
+
✓ Found 5 route(s)
251
+
/ → pages/index.schema.json
252
+
/about → pages/about.schema.json
253
+
/blog → pages/blog/index.schema.json
254
+
/blog/:id → pages/blog/[id].schema.json
255
+
/users/:userId → pages/users/[userId].schema.json
256
+
```
257
+
247
258
#### Route Mapping Rules
248
259
249
260
-`pages/index.schema.json` → `/`
@@ -254,25 +265,23 @@ The serve command will:
254
265
255
266
#### Navigation Between Pages
256
267
257
-
Use the button component with `href` to navigate:
268
+
Use link components or buttons with navigation:
258
269
259
270
```json
260
271
{
261
-
"type": "button",
262
-
"label": "Go to About",
263
-
"href": "/about"
272
+
"type": "div",
273
+
"className": "flex gap-4",
274
+
"body": [
275
+
{
276
+
"type": "button",
277
+
"label": "Go to About",
278
+
"onClick": "() => window.location.href='/about'"
279
+
}
280
+
]
264
281
}
265
282
```
266
283
267
-
Or use link components:
268
-
269
-
```json
270
-
{
271
-
"type": "link",
272
-
"href": "/blog/123",
273
-
"children": "Read Blog Post"
274
-
}
275
-
```
284
+
**Note:** For now, navigation is done through standard links. Schema-level navigation helpers are planned for a future release.
276
285
277
286
### Approach 2: Manual React Router Setup
278
287
@@ -359,66 +368,7 @@ You can also define navigation in your main schema using button click handlers:
359
368
360
369
## Layouts and Nested Routes
361
370
362
-
### Root Layout
363
-
364
-
Create an `app.schema.json` file to define a layout that wraps all pages:
365
-
366
-
```json
367
-
{
368
-
"type": "div",
369
-
"className": "min-h-screen",
370
-
"body": [
371
-
{
372
-
"type": "div",
373
-
"className": "border-b bg-background",
374
-
"body": {
375
-
"type": "div",
376
-
"className": "container mx-auto px-6 py-4",
377
-
"body": [
378
-
{
379
-
"type": "link",
380
-
"href": "/",
381
-
"className": "mr-4",
382
-
"children": "Home"
383
-
},
384
-
{
385
-
"type": "link",
386
-
"href": "/about",
387
-
"className": "mr-4",
388
-
"children": "About"
389
-
},
390
-
{
391
-
"type": "link",
392
-
"href": "/blog",
393
-
"children": "Blog"
394
-
}
395
-
]
396
-
}
397
-
},
398
-
{
399
-
"type": "div",
400
-
"className": "container mx-auto",
401
-
"body": "{{outlet}}"
402
-
}
403
-
]
404
-
}
405
-
```
406
-
407
-
The `{{outlet}}` placeholder is where page content will be rendered.
408
-
409
-
### Nested Layouts
410
-
411
-
Create `_layout.schema.json` files in subdirectories for nested layouts:
412
-
413
-
```
414
-
pages/
415
-
├── blog/
416
-
│ ├── _layout.schema.json → Layout for all /blog routes
417
-
│ ├── index.schema.json → /blog
418
-
│ └── [id].schema.json → /blog/:id
419
-
```
420
-
421
-
**Note:** File-system based routing with automatic route generation is planned for a future release. The documentation above describes the intended behavior.
371
+
**Note:** Layout support with `app.schema.json` and `_layout.schema.json` is planned for a future release. Currently, all routing is handled at the page level.
0 commit comments