A CLI tool to generate pages/layouts/routes
for Next.js projects.
You can install the CLI globally using npm:
npm install -g nextjs-route-generator
To generate a route, use the next-generate
command followed by the route path. You can also specify which files to create using the flags.
npx next-generate "posts/[id]" -p -l -r
This will create the following structure:
pages/
└── posts/
└── [id]/
├── page.tsx
├── layout.tsx
└── route.ts
You can specify which files to generate using the flags:
-
-p
forpage.tsx
orpage.jsx
-
-l
forlayout.tsx
orlayout.jsx
-
-r
forroute.ts
orroute.js
For example, to generate only page.tsx
and layout.tsx
:
npx next-generate "posts/[id]" -p -l
This will create the following structure:
pages/
└── posts/
└── [id]/
├── page.tsx
└── layout.tsx
The tool automatically determines whether your project is using TypeScript or JavaScript based on the presence of tsconfig.json
in your project root. It will generate files with appropriate extensions:
- For TypeScript:
.tsx
and.ts
- For JavaScript:
.jsx
and.js
MIT