Aviary
Integrations

nestjs-inertia

Pages, shared props, and Inertia router navigation.

When you build a NestJS + Inertia app, register the inertia extension and point pages.glob/app.moduleEntry at your app. The codegen then additionally:

  • discovers your Inertia pages and emits pages.d.ts + components.json;
  • reads shared props from InertiaModule.forRoot({ share });
  • emits a typed navigate() helper backed by the Inertia router.
pnpm add -D @dudousxd/nestjs-inertia-codegen-extension
nestjs-codegen.config.ts
import { defineConfig } from '@dudousxd/nestjs-codegen';
import { nestjsInertiaCodegen } from '@dudousxd/nestjs-inertia-codegen-extension';

export default defineConfig({
  pages: { glob: 'resources/pages/**/*.tsx' },
  contracts: { glob: 'src/**/*.controller.ts' },
  app: { moduleEntry: 'src/app.module.ts' },
  codegen: { outDir: 'resources/generated' },
  extensions: [nestjsInertiaCodegen()],
});

Typed navigation

import { navigate } from '../generated/api';

navigate('users.show', { params: { id: '42' } }); // typed route + params

When nestjsInertiaCodegen() is registered, the generated api.ts imports router from @inertiajs/react for this helper; without the extension it isn't imported at all.

The pages typing augments @dudousxd/nestjs-inertia's InertiaPages interface, so inertia.render('Users/Index', props) is checked against the discovered page props.

On this page