T
TanStack2y ago
like-gold

How to use file-based routing for deep url structures

I'm struggling a lot with file-based routing, for example using urls like: $id1/aaa/$id2/bbb/$id3/ccc/$id4 I've been reading the docs, which are pretty unclear, and trying all kinds of combinations of _ prefix and suffixes. I'm having to restart the server every time to test them because the tsr command doesn't seem to work. I have a feeling what I'm trying to do is beyond the capabilities of this router, seems like it's not been tested with long paths. You can't use more than one underscore in the file name, or else it just puts it in the path. I'm also seeing mismatches from what is shown in the file route path and what is shown in the generated route tree I can get it to work using the code-based setup. Here's how I've set that up, with the path set on each route in the comment next to each route:
const routeTree = rootRoute.addChildren([
adminDashboardRoute, // path = /
loginRoute, // path = /login
clientRoute.addChildren([ // path = /$clientId
dashboardRoute, // path = /
surveysRoute, // path = /surveys
surveyRoute, // path = /surveys/$surveyId
roomsRoute, // path = /surveys/$surveyId/rooms
roomRoute, // path = /surveys/$surveyId/rooms/$roomId
]),
]);
const routeTree = rootRoute.addChildren([
adminDashboardRoute, // path = /
loginRoute, // path = /login
clientRoute.addChildren([ // path = /$clientId
dashboardRoute, // path = /
surveysRoute, // path = /surveys
surveyRoute, // path = /surveys/$surveyId
roomsRoute, // path = /surveys/$surveyId/rooms
roomRoute, // path = /surveys/$surveyId/rooms/$roomId
]),
]);
I don't want the deeper route components to be nested inside each other, if that helps Here is where I got to with file-based, but I can't get any further, and this was all trial and error and it doesn't seem to make sense https://cdn.discordapp.com/attachments/1007702008448426065/1199769887892062350/Screenshot_2024-01-24_at_17.36.39.png?ex=65c3bfc7&is=65b14ac7&hm=b6614640efd6dc0986bbc3eed708653c0a28745ce3b7954f7f44290be7b9ae48&
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?