Skip to content

Commit 009dbae

Browse files
Copilothotlong
andcommitted
Implement file-system based routing (Next.js-style) for CLI
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent cd26724 commit 009dbae

2 files changed

Lines changed: 421 additions & 95 deletions

File tree

docs/CLI_GUIDE.md

Lines changed: 26 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ objectui serve app.schema.json --host 0.0.0.0 --port 3001
159159

160160
The CLI supports two approaches for routing: **file-system based routing** (recommended, Next.js-style) and manual React Router setup.
161161

162-
### Approach 1: File-System Based Routing (Recommended)
162+
### Approach 1: File-System Based Routing (Recommended)
163163

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.
165165

166166
#### Directory Structure
167167

@@ -177,7 +177,7 @@ my-app/
177177
│ │ └── [id].schema.json → /blog/:id
178178
│ └── users/
179179
│ └── [userId].schema.json → /users/:userId
180-
└── app.schema.json (optional layout)
180+
└── app.schema.json (optional, reserved for future layout support)
181181
```
182182

183183
#### Example Page Schemas
@@ -244,6 +244,17 @@ The serve command will:
244244
3. Generate route configuration based on file structure
245245
4. Set up the application with all routes
246246

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+
247258
#### Route Mapping Rules
248259

249260
- `pages/index.schema.json``/`
@@ -254,25 +265,23 @@ The serve command will:
254265

255266
#### Navigation Between Pages
256267

257-
Use the button component with `href` to navigate:
268+
Use link components or buttons with navigation:
258269

259270
```json
260271
{
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+
]
264281
}
265282
```
266283

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.
276285

277286
### Approach 2: Manual React Router Setup
278287

@@ -359,66 +368,7 @@ You can also define navigation in your main schema using button click handlers:
359368

360369
## Layouts and Nested Routes
361370

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.
422372

423373
## FAQ
424374

0 commit comments

Comments
 (0)