After discussing the recent issues of the Hilla FS Router internally, we found several issues that need to be addressed.
The main issue is to understand how different variable parameters interact with each other.
We have three variable parameters that are already implemented but for now they could incorrectly interact with each other.
They are the following:
- Required Parameter (
users/:userId
). - Optional Parameter (
users/:userId?
) - Wildcard (
users/*
)
We also have a couple of specific route types that allow us to handle route nesting:
- Layout (
@layout.tsx
file). This route type allows us to specify a wrapper around all the descendants for the current URL segment. - Index (
@index.tsx
file). This route type allows us to specify a resolution for the parent route segment that could also have children.
For example, if you havehttps://example.com/users
which is a list, and you also want each user to have a link likehttps://example.com/users/123
, you must use Index route type for the list.
Also, to make Flow routes integrated seamlessly we have the wildcard route with a Flow component as a fallback for each list of children at any nesting level.
So, let’s check what interactions we have.
Required/Optional/Wildcard
If we have a mix of Required/Optional/Wildcard routes including Flow Fallback the route that comes later will never be called because the route that comes first will take over it
NOTE: partial URL parameters are not supported in ReactRouter 6
export default {
path: 'users',
children: [
{ path: ':userId' },
{ path: '*' }, // will never be resolved
]
}
It makes impossible to use any Flow route in the directory that contains a variable parameter route.
It also requires us to sort the routes more thoroughly because if the variable route is sorted before the regular route, it won’t allow the regular route to resolve.
So, my question here is the following:
- What is the expected router behavior here for you?
- Is it ok to omit the Flow Fallback if there is any of variable route present in the directory?
- How should we handle multiple variable routes in a single directory? Should it be just a compile-time error with an undefined behavior?
About actions that are following from the description, I have these:
- The variable route should always be at the end of the sequence of routes.
Optional
The Optional route looks redundant because in the easy case it could be simply re-made by using Index and Required routes.
The Optional route also creates a set of complicated scenarios, e.g. how the URL should be resolved in this case:
/users/:a?/:b/:c?/list
The Optional routes exist in React Router but there is pretty limited documentation about how to use it correctly.
My questions here are the following:
- What would you expect from the router with Optional route?
- How to resolve the complex cases like I’ve mentioned above?
- Do we need to have the optional route as a part of FS Router at all?
File vs Index
We also have a case when the user has specified both a directory and a file with the same name.
The question: what is the expected outcome for this case, especially considering everything said above.
The possible solutions are the following:
- You cannot create a file and a directory with the same name. To implement this scenario, use Index route.
- The file has the bigger priority over the directory.
I mostly tend to choose the first option but in the internal discussion we chose the second one.
However, it was done before the issues above were found.
My questions here are the following:
- What would you expect from the router in this case?