Retrieve dynamic URL params via router middleware
Unanswered
West African Lion posted this in #help-forum
West African LionOP
Using the following URL as an example, how can i retrieve the user_id value via the router middleware? I need to retrieve all dynamic values in the URL as I will be validating them, such as making sure they are a valid UUID etc before calling next()
www.example.com/users/[user_id_here]/stats?type=all
www.example.com/users/[user_id_here]/stats?type=all
// The following just returns the stats query param without the dynamic user_id
const { searchParams } = new URL(request.url)2 Replies
West African LionOP
It seems the better approach for this would be for me to validate directly within the route handler as I can get the params via context.
export async function POST(request: NextRequest, { params }: { params: {} }) {}yes i agree, the logic should be in the route handler itself