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
Copy file name to clipboardExpand all lines: README.md
+58-8Lines changed: 58 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ Supports:
13
13
-**Dynamic routes**
14
14
-**Error boundary**
15
15
-**404 page**
16
+
-**Loader support for data fetching**
16
17
17
18
Built for **React Router DOM** + **Vite** — simple, fast, familiar.
18
19
@@ -27,6 +28,7 @@ Built for **React Router DOM** + **Vite** — simple, fast, familiar.
27
28
✅ Dynamic routes with `[slug]`, `[...slug]`, `[[slug]]`\
28
29
✅ Error boundaries via `error.jsx`\
29
30
✅ 404 Not Found handling with `404.jsx`\
31
+
✅ Loader support for data fetching `loader.jsx`\
30
32
✅ Fully type-safe (TypeScript supported)
31
33
32
34
---
@@ -36,7 +38,6 @@ Try it on StackBlitz:
36
38
37
39
[](https://stackblitz.com/edit/react-next-router-example?file=src%2Fmain.jsx)
38
40
39
-
40
41
---
41
42
42
43
## 📦 Install
@@ -58,38 +59,57 @@ src/
58
59
│ └── page.jsx # '/about'
59
60
├── blog/
60
61
│ ├── [slug]/
61
-
│ │ └── page.jsx # '/blog/:slug'
62
+
│ │ ├── page.jsx # '/blog/:slug'
63
+
│ │ └── loader.jsx # Loader for data fetching
62
64
│ └── layout.jsx # Layout for '/blog/*'
63
65
├── (admin)/
64
66
│ ├── dashboard/
65
67
│ │ └── page.jsx # '/dashboard'
66
68
│ └── layout.jsx # Layout for group
67
-
├── error.jsx # Error boundary
68
-
└── 404.jsx # Not Found page
69
+
├── error.jsx # Error boundary
70
+
├── 404.jsx # Not Found page
71
+
├── pending.jsx # Pending component (renders while loading)
69
72
```
70
73
74
+
75
+
> You can `loader.jsx` alongside any `page.jsx` to fetch data before rendering the page.
76
+
> Add a `app/pending.jsx` file to show a loading UI while the loader is running.
|`app/blog/[slug]/loader.jsx`| Data loader for `/blog/:slug`|
136
+
|`app/pending.jsx`| Loading UI while data is fetched |
137
+
138
+
139
+
## 🧪 useAppRouter Hook
140
+
You can now use the useAppRouter() hook to get a JSON structure of all matched routes. This is useful when you want to inspect or manipulate the route config manually — for example, inside a custom RouterProvider or createBrowserRouter setup.
141
+
142
+
```jsx
143
+
import { useAppRouter } from"react-next-router";
144
+
145
+
constMyComponent= () => {
146
+
constrouter=useAppRouter();
147
+
console.log(router);
148
+
return<div>Check the consolefor the matched routes!</div>;
149
+
};
150
+
```
115
151
116
152
---
117
153
@@ -166,6 +202,20 @@ app/
166
202
167
203
---
168
204
205
+
## 🛠️ Loaders (Data Fetching)
206
+
207
+
Add a `loader.jsx` file alongside any `page.jsx` to fetch data before rendering the page. The returned value will be passed as the `data` prop to the sibling `page.jsx` component.
0 commit comments