Best Practices for File-Based Routing with i18n, Sidebar Navigation, and Auth in TanStack Router #4340
Unanswered
sulejmanhoxha
asked this question in
Q&A
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.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using file-based routing in my app, and I want each route to follow a consistent structure. Here's an example folder layout I'm aiming for:
Every route (like
invoice
) has its own folder with optional subroutes (edit
,detail
) and support folders (-data
,-forms
,-languages
, etc.).What I want to implement:
Sidebar Navigation
A sidebar showing all available pages, with nested accordions representing sections (
dashboard
), subsections (documents
,reports
), and final links to pages likeinvoice
ormonthly-summary
. For example:Multi-language support with URL prefixes
The app must support exactly 4 languages: English (
en
), Montenegrin (srb
), Albanian (al
), and German (ger
).Each page will have a
-languages
folder with JSON files nameden.json
,srb.json
,al.json
, andger.json
.Language is part of the URL, e.g.
/en/dashboard/documents/invoice
,/srb/dashboard/documents/invoice
.I want to dynamically load the correct translation file based on the
:lang
URL param.Authorization & role-based access
The sidebar should only show links users have permission to see based on their roles.
Also, routes should be protected so unauthorized users can’t access restricted pages.
Default query parameters per route
Some routes should have default query params. For example, the
invoice
route should default to?sort=-createdAt
.Sidebar route entries might look like this:
TypeScript typing & scalability
I want the sidebar navigation to be fully typed with TypeScript, including the allowed roles, paths, labels, and optional query params.
Since this app will have thousands of pages, I want a solution that scales well and can be generated or maintained easily.
Question:
What’s the best way to handle all this using TanStack Router in a maintainable, efficient, and secure way?
Particularly interested in:
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions