Hi everyone ,
I’m trying a few things with the new File Router coming in Hilla 24.4. I would like to create a nested route like orders/:orderId/items/:itemId and I wonder how to achieve that with File Router?
Using a NavLink like <NavLink to="/orders/1">#1</NavLink> works fine.
Using a NavLink like <NavLink to="/orders/3/items/1">#3.1</NavLink> redirects to the default " No views found" view.
Any ideas how to structure my folders and files to achieve the desired nested route?
Your views/orders/items/{itemId}.tsx file corresponds to a URL like orders/items/1.
The trick is to use the {param} syntax also for directory names. The route orders/:orderId/items/:itemId is thus supposed handled by a file named views/orders/{orderId}/items/{itemId}.tsx. There were some reports of problems with this structure last week but I don’t remember if anyone looked into that yet.
Note that you can potentially make the structure slightly easier to understand if you rename views/orders/{orderId}.tsx to views/orders/{orderId}/@index.tsx. It’s mostly a matter of taste but it’s at least in my mind slightly clearer to not have two different things with {orderId} directly in the name.