Mapped Object App Router Hack #68103
Unanswered
buchananwill
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
There are many things I really like about the Next.JS framework in terms of DX. However, I've recently started to find the file system-based App router extremely limiting for DRY and refactoring. The main issues I have are:
It could be that I've been approaching routing wrongly, and if it sounds like I'm making any noob errors then feel free to suggest solutions. However, my current escape hatch is to entirely abandon the vast majority of my directory structure and page.tsx files, in favour of a single [[...pathVariables]] slug, that captures all pages. I then use these types, and a recursive pattern matching function to resolve the given url into the Component value of a navTreeData object.
This kind of feels against the grain of the App Router documentation, but it's massively simplified the process of adding site routes or refactoring existing ones. Has anyone else done anything like this? Am I reinventing a wheel here?
Types
Pattern Matcher
Example Object
Beta Was this translation helpful? Give feedback.
All reactions