Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
unflatten-next-routes
Advanced tools
A CLI tool to simplify Next.js routing by allowing developers to work with a flat route structure
Enabling flat routes for Next.js
With the introduction of Next.js 13, a new folder-based routing mechanism was unveiled. While this approach offers powerful and flexible routing capabilities, it brings with it the challenge of managing deeply nested route files. In large projects with a myriad of routes, locating a specific route or deciphering the intricate structure of the application becomes increasingly complex.
Enter unflatten-next-routes
.
Designed specifically for Next.js 13, unflatten-next-routes
is a CLI tool that allows developers to work with a flat route file structure that is easier to manage and understand. With unflatten-next-routes
your routes can be structured like this:
app/
|-- shop/
|-- routes/
|-- basket.(page).tsx
|-- product.(page).tsx
|-- product.[id].(page).tsx
... and unflatten-next-routes
will ensure that these routes are transformed into the nested format that Next.js expects.
To start using the CLI tool, run the following command in the Next.js project root:
npx unflatten-next-routes@latest
This will initiate the tool in watch mode. Then add flat route files within any /routes/
folder located within the app
directory. As you add, rename, or remove these flat route files, the equivalent nested route file will be generated or updated within a parallel /(.routes)/
directory.
Example:
app/
|-- shop/
|-- (.routes)/
| |-- basket/
| | |-- page.tsx
| |-- product/
| |-- page.tsx
| |-- [id]/
| |-- page.tsx
|-- routes/
|-- basket.(page).tsx
|-- product.(page).tsx
|-- product.[id].(page).tsx
Note: The
/(.routes)/
directory should be considered as "private", similar to the.next
directory that Next.js uses for its build output. Files within this directory are auto-generated and should not be manually edited.
Flat routes can be created for page.tsx
, layout.tsx
, loading.tsx
, error.tsx
and route.tsx
files. All that is required is for their flat route equivalent filenames to end with .(page).tsx
, .(layout).tsx
, .(loading).tsx
, .(error).tsx
and .(route).tsx
.
Example:
/app/shop/routes/basket.(page).tsx
/app/shop/routes/product.(layout).tsx
/app/shop/routes/product.[productId].(page).tsx
/app/admin/routes/settings.(page).tsx
For flat index route files, there's no need to prefix the route filename. For instance, the admin homepage will be:
/app/admin/(page).tsx
/app/admin/(error).tsx
The tool supports .tsx, .jsx, and .js file extensions for flat route files.
v0.1.3
.ts
extension (00dc28c)FAQs
A CLI tool to simplify Next.js routing by allowing developers to work with a flat route structure
The npm package unflatten-next-routes receives a total of 0 weekly downloads. As such, unflatten-next-routes popularity was classified as not popular.
We found that unflatten-next-routes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.