wobsoriano / trpc-nuxt

End-to-end typesafe APIs in Nuxt applications.
trpc-nuxt.vercel.app
MIT License
687 stars 39 forks source link

[QUESTION] Get Route Params #90

Closed angelhdzdev closed 1 year ago

angelhdzdev commented 1 year ago

I'm using namespaces, so my route is /trpc/auth.login where auth is the namespace for the authRouter, and has a login procedure.

Now I'm trying to read route params.

So my url is /trpc/auth.login/SomeID

And the procedure namespace:

const authRouter = router({
 "login/:id": login
})

image

Then in the context:

export function createContext (_event: H3Event) {

  return {params: _event.context.params}
}

And I get:

image

I spent the whole day reading the tRPC docs, and asking the A.I. ( I don't write its name or I'll get SPAM).

angelhdzdev commented 1 year ago

Update

Of course, in Nuxt 3, the route params are defined in the route files like server/api/some-route/[someParam].ts.

I also tried that syntax:

const authRouter = router({
 "login/[id]": login
})