1.3.0 • Published 1 year ago
@pigsty/next-routes-list v1.3.0
next-routes-list
Forked from https://github.com/Emiyaaaaa/next-routes-list
Generate list of routes based on Next.js source code
Support
- App routes
- Page routes
Install
pnpm add next-routes-list -DUsage
1. Run script
add script to package.json:
{
"script": {
"generate-next-routes-list": "generate-next-routes-list"
}
}If you use src directory:
{
"script": {
"generate-next-routes-list": "cd src && npx generate-next-routes-list"
}
}then run npm script:
npm run generate-next-routes-list2. Import routes
TODO: incomplete readme, but basically you can call getNextRoutesWithMatchers and have a list of all routes + regular expression that you can use to test URL.pathname
import { getNextRoutesWithMatchers } from 'next-routes-list'
console.log(getNextRoutesWithMatchers())
/**
[
'/',
'/about',
'/posts/[id]',
...
]
*/Example
next projct is here, generate result is: here.
Contribute
feel free to contribute anything or report any issues.