next-app-router-scanner
v1.0.6
Published
A package to scan and generate a structured array of Next.js App Router routes (development mode only)
Downloads
35
Maintainers
Readme
Next App Router Scanner A package to scan and generate a structured array of Next.js App Router routes. Works only in development mode. Installation npm install next-app-router-scanner
Usage As a CLI npx next-routes --output routes.json --dir ./app
As a Module const { getRoutes } = require('next-app-router-scanner');
async function main() { try { const routes = await getRoutes(); console.log(JSON.stringify(routes, null, 2)); } catch (error) { console.error(error.message); } }
main();
Output Format The package generates an array of route objects with the following structure: [ { "path": "/", "isPage": true, "isError": true, "isLoading": true, "isLayout": true, "items": [ { "path": "/about", "isPage": true, "isError": false, "isLoading": false, "isLayout": false, "items": [] } ] } ]
Options
--output : Specify the output JSON file path (default: routes.json). --dir : Specify the app directory path (default: ./app).
Notes
This package only works in development mode (NODE_ENV=development). In production mode, it returns an empty array. Supports dynamic routes ([id]), catch-all routes ([...slug]), and optional catch-all routes ([[...slug]]). Includes detection of layout.tsx and layout.js files with the isLayout property.
License MIT
