1.0.12 • Published 8 months ago
list-routes-next v1.0.12
Gets all available routes in Next
pnpm buildpnpm publishInstall
pnpm install --save-dev list-routes-next@latestOr run once without installing:
pnpm dlx list-routes-next@latestUsage
Step 1. Run script
Add script to package.json:
{
"script": {
"generate-list-routes-next": "generate-list-routes-next"
}
}Or if you using src directory:
{
"script": {
"generate-list-routes-next": "cd src && npx generate-list-routes-next"
}
}Or if you want specify the output file:
{
"script": {
"generate-list-routes-next": "generate-list-routes-next -o routes.ts"
}
}Then run npm script:
pnpm run generate-list-routes-nextStep 2. Import routes
import { routes } from "list-routes-next";
// 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-list-routes-next -o routes.ts |
Finding Imports
To find which files import a specific file:
npx find-imports-next <base-directory> <tsconfig-path> <relative-path-to-target-file>Example:
npx find-imports-next ./src ./tsconfig.json components/Button.tsxThis will output a list of all files that import the specified target file.
Finding File Path for a Route
To find the corresponding file path for a given route:
npx find-route-file-next <route> [base-directory]Example:
npx find-route-file-next /blog/my-post ./srcThis will output the file path that corresponds to the given route. For example:
/src/app/blog/[slug]/page.tsxThe tool handles:
- App Router routes (
/appdirectory) - Pages Router routes (
/pagesdirectory) - Dynamic routes (e.g.,
[slug],[...catchAll]) - Route groups (directories with parentheses)
- Parallel routes (
@folder) - Intercepting routes
Development
Local Setup
- Build the package:
pnpm build- Link the package globally:
npm link- Now you can use the CLI commands locally:
npx generate-list-routes-next
npx find-imports-next
npx find-route-file-nextMaking Changes
- Make your changes in the source files
- Rebuild the package:
pnpm build- The linked projects will automatically use the new version
Unlinking
To remove the global link:
pnpm unlink --global list-routes-nextAlternative: Local Installation
Instead of linking, you can install directly from the local filesystem:
pnpm add --save-dev /absolute/path/to/packages/routes-list