next-generate-path 0.0.2 → 0.0.3
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 +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,6 +107,24 @@ generatePath("/docs/[...segments]", { segments: ["getting-started"] });
|
|
|
107
107
|
// => "/docs/getting-started"
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
### API routes — `route.ts`
|
|
111
|
+
|
|
112
|
+
API route handlers are included in the `ParamMap` too, so `generatePath` works for building API URLs:
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
generatePath("/api/health");
|
|
116
|
+
// => "/api/health"
|
|
117
|
+
|
|
118
|
+
generatePath("/api/products/[id]", { id: "42" });
|
|
119
|
+
// => "/api/products/42"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
This is useful for `fetch` calls where you want type-safe API paths:
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
const res = await fetch(generatePath("/api/products/[id]", { id: productId }));
|
|
126
|
+
```
|
|
127
|
+
|
|
110
128
|
### Route groups — `(folder)`
|
|
111
129
|
|
|
112
130
|
Route groups don't affect URLs. A page at `app/(marketing)/pricing/page.tsx` is just `/pricing`:
|
|
@@ -125,6 +143,8 @@ Next.js with `typedRoutes: true` generates a `ParamMap` interface in `.next/type
|
|
|
125
143
|
interface ParamMap {
|
|
126
144
|
"/": {}
|
|
127
145
|
"/about": {}
|
|
146
|
+
"/api/health": {}
|
|
147
|
+
"/api/products/[id]": { id: string }
|
|
128
148
|
"/blog/[slug]": { slug: string }
|
|
129
149
|
"/products/[id]": { id: string }
|
|
130
150
|
"/products/[id]/reviews": { id: string }
|