Nest Router Module

1.0.9 · abandoned · verified Sun Apr 19

nest-router is a module for the NestJS framework designed to provide a hierarchical and modular approach to route organization. It allows developers to define a tree-like structure for application routes, automatically prefixing controller paths based on parent module configurations. For example, a child module's routes will inherit the parent's prefix, resulting in `/parent/child/route` rather than just `/child/route`. This addresses a common routing organization challenge in older NestJS versions (specifically prior to features like `APP_BASE_URL` or later routing enhancements). The last stable version is 1.0.9, published 7 years ago. This package is largely incompatible with modern NestJS versions (v6+ and especially v10+, with NestJS 11.1.19 being the latest as of April 2026). Its primary differentiator was its ability to structure routes in a more organized, tree-like manner for NestJS applications relying on a specific routing pattern.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a hierarchical route structure using `nest-router` and integrate it into a NestJS application. It shows how parent modules define prefixes for their children's routes.

import { Module } from '@nestjs/common';
import { RouterModule, Routes } from 'nest-router';

// Imagine these are actual NestJS modules with controllers
class CatsModule {}
class DogsModule {}
class NinjaModule {}

const routes: Routes = [
  {
    path: '/ninja',
    module: NinjaModule,
    children: [
      {
        path: '/cats',
        module: CatsModule,
      },
      {
        path: '/dogs',
        module: DogsModule,
      },
    ],
  },
];

@Module({
  imports: [
    RouterModule.forRoutes(routes), // Set up the routes hierarchy
    CatsModule,
    DogsModule,
    NinjaModule // All modules must also be imported normally
  ],
})
export class ApplicationModule {}

// Example of how a controller path would resolve:
// A controller in CatsModule with @Controller('my-cat')
// would have a full path of /ninja/cats/my-cat

view raw JSON →