Open benjaminweb opened 16 hours ago
Maybe you can help me out with a design problem here. I wanted the ability for a user to define subroutes, but also a "main" route:
data MyRoute
= Main
| One
| Two
deriving (Generic, Route)
So the user can visit /
and get Main
, /one
for One, etc. As you've noticed, /main
still works.
The route
function assumes you want to use this pattern. Take a look at the definition of routePath
: it's doing this deliberately https://github.com/seanhess/hyperbole/blob/main/src/Web/Hyperbole/Route.hs#L52. I've found I use this pattern more often than I want to avoid it, and have all the constructors be peers.
Do you have any suggestions? One alternative would be to NOT assume the user wants this and require them to specify defRoute
that the user would need to make the presence of a default route explicit:
-- This would work as you expect, with /one, /two, and /three generated
data MyRoute
= One
| Two
| Three
deriving (Generic, Route)
-- This would work like the library does now
data MyRoute
= Main
| One
| Two
deriving (Generic)
instance Route MyRoute where
defRoute = Just Main -- we change this to a maybe to make it optional
Let me know your thoughts!
route (ResultRequested x) id $ "link to share"
yields "/resultrequested" for Route1 where "/resultrequested/Route1" would be expected (for any other like Route2 "resultrequested/Route2" are generated