You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a set of pages that can either be accessed in the context of a user, or not. A simplified example would be that I have a Vehicles page. Vehicles are available for all users. Adding vehicles would be done at vehicles._index.tsx, editing at vehicles.edit.tsx and so on.
When I'm looking at a user users.$userId._index.tsx I'd want the user to still list/edit/add vehicles. If I simply redirect them to vehicles._index.tsx I lose the context of the user.
There are many solutions to what I'm trying to achieve. I could pass the userId as a querystring parameter, but then i'd have to remember to handle that in all the vehicle pages and pass it from _index to edit etc.
Another option is to mirror all the vehicle routes users.$userId.vehicles._index.tsx and re-export the corresponding view/loader/action functions. But that's just as brittle as the query string option.
I guess ideally I'd be able to express the vehicle routes as such (users.$userId.)vehicles._index.tsx where I make the entre user path segment optional. All I need to keep in mind with this approach is to handle the optional userId, and redirect accordingly.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a set of pages that can either be accessed in the context of a user, or not. A simplified example would be that I have a Vehicles page. Vehicles are available for all users. Adding vehicles would be done at
vehicles._index.tsx
, editing atvehicles.edit.tsx
and so on.When I'm looking at a user
users.$userId._index.tsx
I'd want the user to still list/edit/add vehicles. If I simply redirect them tovehicles._index.tsx
I lose the context of the user.There are many solutions to what I'm trying to achieve. I could pass the userId as a querystring parameter, but then i'd have to remember to handle that in all the vehicle pages and pass it from _index to edit etc.
Another option is to mirror all the vehicle routes
users.$userId.vehicles._index.tsx
and re-export the corresponding view/loader/action functions. But that's just as brittle as the query string option.I guess ideally I'd be able to express the vehicle routes as such
(users.$userId.)vehicles._index.tsx
where I make the entre user path segment optional. All I need to keep in mind with this approach is to handle the optional userId, and redirect accordingly.Link to the discord chat where I asked for help about this initially: https://discord.com/channels/770287896669978684/1126608389426909184/1126608389426909184
Beta Was this translation helpful? Give feedback.
All reactions