Easy generate all available routes in Next.js .
- App routes
- Page routes
npm install --save-dev next-routes-list@latest
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
import { routes } from "next-routes-list";
// or if you specify the output file
import { routes } from "./routes.ts";
console.log(routes);
/**
[
'/',
'/about',
'/posts/[id]',
...
]
*/
Option | Type | Description | Example |
---|---|---|---|
-o |
string | set the output routes file path | npx generate-next-routes-list -o routes.ts |
Here is a next.js project, here is the generate result.
Feel free to contribute anything or report any issues.