0Pricing
tRPC End-to-End Type Safe APIs · Lesson

Merging and Nesting Routers

Learn to organize a growing tRPC API by composing multiple sub-routers into a single nested app router.

Why Split Routers?

As your API grows, one giant router becomes hard to read. tRPC lets you build small focused sub-routers and merge them.

A Users Sub-Router

Group all user-related procedures together.

export const userRouter = router({
  list: publicProcedure.query(() => getUsers()),
  byId: publicProcedure.input(z.string()).query(({ input }) => getUser(input)),
});

All lessons in this course

  1. Structuring with tRPC Routers
  2. Implementing Query Procedures
  3. Developing Mutation Procedures
  4. Merging and Nesting Routers
← Back to tRPC End-to-End Type Safe APIs