Skip to content

Emiyaaaaa/next-routes-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

next-routes-list

Easy generate all available routes in Next.js .

Support

  • App routes
  • Page routes

Install

npm install --save-dev next-routes-list@latest

Usage

Step 1. Run script

Add script to package.json:

{
  "script": {
    "generate-next-routes-list": "generate-next-routes-list"
  }
}

Or if you using src directory:

{
  "script": {
    "generate-next-routes-list": "cd src && npx generate-next-routes-list"
  }
}

Or if you want specify the output file:

{
  "script": {
    "generate-next-routes-list": "generate-next-routes-list -o routes.ts"
  }
}

Then run npm script:

npm run generate-next-routes-list

Step 2. Import routes

import { routes } from "next-routes-list";
// or if you specify the output file
import { routes } from "./routes.ts";


console.log(routes);
/**
[
  '/',
  '/about',
  '/posts/[id]',
  ...
]
*/

Options

Option Type Description Example
-o string set the output routes file path npx generate-next-routes-list -o routes.ts

Example

Here is a next.js project, here is the generate result.

Contribute

Feel free to contribute anything or report any issues.