Next.js Discord

Discord Forum

Dynamic route undefined slug in route handler.

Answered
Clown posted this in #help-forum
Open in Discord
I am using NextJS 13.4.7. I am using a dynamic route(route handler/app directory) and the slug seems to return undefined:

app/api/organization/[userid]/route.ts

import { NextResponse } from "next/server";

export async function GET(
  request: Request,
  { params }: { params: { slug: string } },
) {
  const slug = params.slug;
  console.log(request.url);
  console.log(slug);
  return new NextResponse("Hello From Organization route! User ID: ", {
    status: 200,
  });
}


output:
http://localhost:3000/api/organization/64e32b2bcc2a4d4805639847
undefined


The slug returns undefined as can be seen. If its any help, i am fetching this in a middleware.
Answered by European sprat
err "userid"

it maps to whatever the folder is named as with [userid]
View full answer

4 Replies

European sprat
it's "userId" not "slug"
European sprat
err "userid"

it maps to whatever the folder is named as with [userid]
Answer
oh did i miss that in the documentation or its just not written correctly :/
thanks anyways