Group of routes can be controlled by middleware?
Answered
Saltwater Crocodile posted this in #help-forum
Saltwater CrocodileOP
If you see the image, you can see there is a group of routes called "(root)" and also there is one route called "sign-in",
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export async function middleware(request: NextRequest) {
// How can I a conditional for this routes??
}
export const config = {}10 Replies
Saltwater CrocodileOP
The route group's name wont be in the conditional basically
You use the exact same path as you would in the url
Answer
^ if i remember correctly
Saltwater CrocodileOP
So if I have /dashboard, /profile ..... I need to write for each route the if request.nextUrl.pathname.startsWith("/dashboard)....?
Yeah, without the (root) in the startWith string
Saltwater CrocodileOP
I get it, thanks 😄
@Saltwater Crocodile I get it, thanks 😄
Mark the answer pls
Original message was deleted
@Clown Mark the answer pls
Saltwater CrocodileOP
I think I'm done