forked from luisFilipePT/shadcn-ui-theme-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
23 lines (21 loc) · 722 Bytes
/
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
import { NextResponse, type NextRequest } from "next/server"
import themes from "@/themes/index.json"
// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
// Check if there is any supported theme in the pathname
const pathname = request.nextUrl.pathname
// Redirect if there is no theme
if (pathname === "/") {
console.log("Redirecting to default theme", pathname.split("/")[1])
// // The new URL is now /default
return NextResponse.redirect(new URL(`/default/`, request.url))
}
}
export const config = {
matcher: [
// Skip all internal paths (_next)
"/((?!_next).*)",
// Optional: only run on root (/) URL
"/",
],
}