@evolonix/react-router-next 0.2.0 → 0.2.1
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.
- package/README.md +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,6 +111,8 @@ File-name conventions inside a route folder:
|
|
|
111
111
|
|
|
112
112
|
For each route folder the plugin exposes a virtual module — `virtual:react-router-next/<route-key>` — that mirrors the folder layout, with the root represented as `_root`:
|
|
113
113
|
|
|
114
|
+
The runtime renders each `page.tsx` with its `RouteProps` already wired up — `params` is parsed from the URL (typed from the folder name) and passed in as a prop, so the component can destructure it directly without calling `useParams`/`useRouteParams`. The virtual module only exports `RouteProps` (and `useRouteParams`) for routes that actually have params; paramless routes can omit the prop entirely.
|
|
115
|
+
|
|
114
116
|
```tsx
|
|
115
117
|
// src/app/posts/[postId]/page.tsx
|
|
116
118
|
import type { RouteProps } from "virtual:react-router-next/posts/[postId]";
|
|
@@ -134,6 +136,16 @@ import { generate as generatePost } from "virtual:react-router-next/posts/[postI
|
|
|
134
136
|
<NavLink to={generatePost({ postId: "1" })}>First post</NavLink>;
|
|
135
137
|
```
|
|
136
138
|
|
|
139
|
+
```tsx
|
|
140
|
+
// src/app/posts/[postId]/page.tsx
|
|
141
|
+
import { useRouteParams } from "virtual:react-router-next/posts/[postId]";
|
|
142
|
+
|
|
143
|
+
export default function PostPage() {
|
|
144
|
+
const { postId } = useRouteParams();
|
|
145
|
+
return <article>Post id: {postId}</article>;
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
137
149
|
The runtime hook `useRouteParams` is also re-exported from the package itself if you'd rather not pin the route literal:
|
|
138
150
|
|
|
139
151
|
```tsx
|
package/package.json
CHANGED