SolidStart unknown number of optional nested route parameters
Hi, looking if there's a way to set up file based routes where there's an unknown number of optional nested routes.
So could be
/:a?/:b?/:c?/.../:f?...
But seems might have to then be array of args cause we don't have names. So for now just going 3-4 levels explicitly like
which is anyway all I likely need so may be fine, but wondering if there was a way.
Thanks8 Replies
I tried combining the nested and optional thing with catch all
...
but unless I did it wrong I don't think that's the intended use for itdid you call the route file
[...allroutes].tsx
? (allroutes
can be replaced by anything)
https://start.solidjs.com/core-concepts/routing#catch-all-routes
This should explain it pretty wellif you only want to have three levels, you have to work with folder names and index files.
here, these routes work:
/test/:anything
/test/:anything/:anything
/test/:anything/:anything/:anything
okay I think I get it, it just returns one params right? and then would have to split the string right?
idk why was expecting to still get multiple params from
useParams
yes if you use the [...anything].tsx approach, the route parts will be combined.
for example
/firstpart/secondpart/anything
will return /firstpart/secondpart/anything
okay great thank you
you're welcome!
If you're using the "fixed" sub routes approach, you can access the parts individually as expected. For my example above, it would be:
yeaa awesome 🔥