@solidrt/router 0.0.63 → 0.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/AGENTS.md +67 -3
  2. package/README.md +56 -0
  3. package/package.json +3 -3
package/AGENTS.md CHANGED
@@ -57,11 +57,75 @@ let item = createRoute({ // a value: typed pa
57
57
  route, or with children a pathless layout. Children match in
58
58
  declaration order.
59
59
 
60
+ ## App structure
61
+
62
+ Split a routed app by role, so the entry reads as a map of the app:
63
+
64
+ ```
65
+ src/
66
+ index.tsx the entry: render(), the window and the route tree
67
+ app.tsx App, the root layout: what stays around every screen
68
+ (background, safe area, nav bar), renders <Outlet />
69
+ state.ts module-scope signals the screens share
70
+ routes/
71
+ home.tsx / one file per screen
72
+ settings.tsx /settings a layout: renders <Outlet />
73
+ settings/
74
+ theme.tsx /settings/theme its children, in a folder of its name
75
+ item.tsx /item/$id exports its route value (typed params)
76
+ not-found.tsx /$
77
+ ```
78
+
79
+ ```tsx
80
+ // src/index.tsx
81
+ render(() => (
82
+ <window title="My app">
83
+ <Router initial="/">
84
+ <Route path="/" component={App}>
85
+ <Route path="/" component={Home} />
86
+ <SettingsRoutes />
87
+ <Route route={item} />
88
+ <Route path="/$" component={NotFound} />
89
+ </Route>
90
+ </Router>
91
+ </window>
92
+ ))
93
+
94
+ // src/routes/settings.tsx: a section that owns its subtree
95
+ export function SettingsRoutes() {
96
+ return (
97
+ <Route path="/settings" component={Settings}>
98
+ <Route path="/" component={Overview} />
99
+ <Route path="/theme" component={Theme} />
100
+ </Route>
101
+ )
102
+ }
103
+ ```
104
+
105
+ - Prefer the JSX tree. The tree as values (`createRouter` at module scope)
106
+ is for code outside the component tree that must reach the router.
107
+ - The file layout is a convention, not a mechanism: a path comes from the
108
+ `path` of its `<Route>` and nothing reads the file system. Name a file
109
+ after the path so a screen is found by its link.
110
+ - index.tsx holds the window and the tree, nothing else. App-wide effects
111
+ (theme, focus navigation) go in `App`; a window prop that changes reads
112
+ state.ts.
113
+ - A screen is one file until it has children; then its children go in a
114
+ folder of its name. While the tree is small, write it whole in index.tsx.
115
+ When a section grows, its file exports a component returning its
116
+ `<Route>` subtree (`SettingsRoutes` above, a fragment for several
117
+ siblings), placed in the tree like a `<Route>`.
118
+ - A screen with typed params defines its `createRoute` value in its own
119
+ file, next to the `useParams(item)` that reads it; index.tsx places it.
120
+ - routes/ holds screens only. Pieces several screens share live beside it.
121
+ - With tabs, the tabs route goes under `App` and its component draws the
122
+ bar.
123
+
60
124
  ## Traps
61
125
 
62
126
  - A `<Route>` is not an element: it evaluates to a route value. Only
63
- `<Route>` elements go under `<Router>` or another `<Route>`; anything
64
- else there throws at mount.
127
+ `<Route>` elements, or components returning them, go under `<Router>`
128
+ or another `<Route>`; anything else there throws at mount.
65
129
  - A route value has one place in one tree: placing it twice (two `<Route
66
130
  route={x}>`, or a `children:` list and a `<Route route={x}>`) throws.
67
131
  - With a JSX tree the router exists only inside `<Router>`: screens reach
@@ -71,7 +135,7 @@ let item = createRoute({ // a value: typed pa
71
135
  screen reads a route only inside a handler or a hook call, never at
72
136
  module scope.
73
137
  - Route components take no props. State a screen shares with others is a
74
- module-scope signal (see the player's parts/app-state.ts), not a prop.
138
+ module-scope signal (state.ts above), not a prop.
75
139
  - A layout route's component must render `<Outlet />` or its child never
76
140
  appears; a route without a component is an outlet alone.
77
141
  - `<Router>` registers its `onBack` before anything it renders. A dialog
package/README.md CHANGED
@@ -50,6 +50,62 @@ A `<Route>` is not an element: it evaluates to a route value that its
50
50
  parent places in the tree, once, when `<Router>` mounts. The router made
51
51
  this way is reached through the hooks (`useNavigate`, `useRouter`).
52
52
 
53
+ ## App structure
54
+
55
+ A routed app splits by role, so the entry reads as a map of the app:
56
+
57
+ ```
58
+ src/
59
+ index.tsx the entry: render(), the window and the route tree
60
+ app.tsx App, the root layout: what stays around every screen
61
+ state.ts module-scope signals the screens share
62
+ routes/
63
+ home.tsx /
64
+ settings.tsx /settings a layout: renders <Outlet />
65
+ settings/
66
+ theme.tsx /settings/theme
67
+ item.tsx /item/$id
68
+ not-found.tsx /$
69
+ ```
70
+
71
+ The entry holds the window and the tree and nothing else. `App` is the
72
+ outermost layout route (the `Shell` above): the background, the safe area,
73
+ a nav bar, the app-wide effects, around an `<Outlet />`. State that screens
74
+ share is module-scope signals in `state.ts`, since route components take no
75
+ props. Each screen is a file under `routes/`, named after its path; a
76
+ screen with children keeps its file as the layout and gets a folder of the
77
+ same name for them.
78
+
79
+ This is a convention, not a mechanism: a path comes from the `path` of its
80
+ `<Route>`, and nothing reads the file system. Naming the file after the
81
+ path is what lets a screen be found by its link.
82
+
83
+ While the tree is small it is written whole in the entry. When a section
84
+ grows, it can own its subtree: a component that returns `<Route>` elements
85
+ is placed in the tree like a `<Route>` (a fragment returns several
86
+ siblings), so the entry keeps one line per section.
87
+
88
+ ```tsx
89
+ // src/routes/settings.tsx
90
+ export function SettingsRoutes() {
91
+ return (
92
+ <Route path="/settings" component={Settings}>
93
+ <Route path="/" component={Overview} />
94
+ <Route path="/theme" component={Theme} />
95
+ </Route>
96
+ )
97
+ }
98
+
99
+ // src/index.tsx
100
+ <Route path="/" component={App}>
101
+ <Route path="/" component={Home} />
102
+ <SettingsRoutes />
103
+ <Route path="/$" component={NotFound} />
104
+ </Route>
105
+ ```
106
+
107
+ `srt init` with the router selected starts a project in this shape.
108
+
53
109
  ## Params are validated
54
110
 
55
111
  A path arrives as strings, and from outside the app they are untrusted. A
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/router",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "license": "MIT",
5
5
  "funding": "https://github.com/sponsors/wellawaretech",
6
6
  "author": "Antoine van Wel",
@@ -15,7 +15,7 @@
15
15
  "AGENTS.md"
16
16
  ],
17
17
  "peerDependencies": {
18
- "@solidjs/signals": "2.0.0-rc.9",
19
- "@solidrt/core": "0.0.63"
18
+ "@solidjs/signals": "2.0.0-rc.13",
19
+ "@solidrt/core": "0.0.65"
20
20
  }
21
21
  }