-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmiddleware.ts
62 lines (57 loc) · 1.85 KB
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// middleware.ts
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
// Define a mapping of old paths to new URLs
const redirects: { [key: string]: string } = {
"/onboardings": "/products?category=Onboarding",
"/carousels": "/products?category=Carousels",
"/parallaxes": "/products?category=Parallaxes",
"/dropdowns": "/products?category=Drop%20Down",
"/pickers": "/products?category=Pickers",
"/headers": "/products?category=Headers",
"/lists": "/products?category=List",
"/arcsliders": "/products?category=Arc%20Sliders",
"/sliders": "/products?category=Sliders",
"/tabbars": "/products?category=Tab%20bars",
"/bottomsheets": "/products?category=Bottom%20Sheets",
"/loaders": "/products?category=Loaders",
"/circular-progress-bars": "/products?category=Circular%20Progress%20Bars",
"/charts": "/products?category=Charts",
"/buttons": "/products?category=Buttons",
"/accordions": "/products?category=Accordions",
"/miscellaneous": "/products?category=Misc",
"/fullapps": "/products?category=Full%20Apps",
}
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
// Use Object.hasOwn to check for property existence
if (Object.hasOwn(redirects, pathname)) {
const destination = redirects[pathname]
return NextResponse.redirect(new URL(destination, request.url))
}
// If no redirect is matched, proceed as normal
return NextResponse.next()
}
// Specify the paths the middleware should run on
export const config = {
matcher: [
"/onboardings",
"/carousels",
"/parallaxes",
"/dropdowns",
"/pickers",
"/headers",
"/lists",
"/arcsliders",
"/sliders",
"/tabbars",
"/bottomsheets",
"/loaders",
"/circular-progress-bars",
"/charts",
"/buttons",
"/accordions",
"/miscellaneous",
"/fullapps",
],
}