Closed aappddeevv closed 5 years ago
Thanks for the issue, @aappddeevv! I agree this is a useful feature. It revealed some insufficiencies in Trail's current design. Ideally, static path elements should not be encoded in the type parameter at all, only the placeholders (like Arg[String]
or Fragment[Int]
).
I have explored some ways to simplify the design and found a way to model the current functionality with tuples instead of HList
s. Could you try out #29 and let me know your thoughts?
With the changes, you could express conditional routes as follows:
class Routes(isProduction: Boolean) {
val root = if (isProduction) Root / "api" / "v2.0" else Root
val users = root / "users" / Arg[String]
}
val devRoutes = new Routes(isProduction = false)
val prodRoutes = new Routes(isProduction = true)
assert(devRoutes.users.parse("/users/test").contains("test"))
assert(prodRoutes.users.parse("/api/v2.0/users/test").contains("test"))
Do I need to try this with a local build? Or did you push something out to the repos?
Whoops, just saw the tag.
So far its working. Ideally you could always change the server routing but that's not always possible e.g. static website server.
Great, thanks for testing!
I need to create a different root based on whether I am running against a dev server or a prod server. The base url is different. But there does not seem to be a way to define a zero path segment so I can form the proper root.
Is there any way to handle this? The SPA client needs to handle this in the SPA's router. If the HList is statically defined, I'm not sure how I would be able to do this.