nextjs-route-generator
v1.6.0
Published
A CLI tool to generate Next.js routes
Downloads
16
Maintainers
Readme
Next.js Route Generator
A CLI tool to generate pages/layouts/routes
for Next.js projects.
Installation
You can install the CLI globally using npm:
npm install -g nextjs-route-generator
Usage
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.
Generate a Route with All Files
npx next-generate "posts/[id]" -p -l -r
This will create the following structure:
pages/
└── posts/
└── [id]/
├── page.tsx
├── layout.tsx
└── route.ts
Generate a Route with Specific Files
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
Determining Project Type
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
License
MIT