
A subsite needs to use the exact same approach of multi-pieces in
order to achieve dynamic routing. So it's not really an either/or
situation. The only thing subsites do is package up a set of
routes/handlers that can be used in other sites.
Michael
On Mon, Apr 4, 2011 at 7:35 PM,
I think we can have our cake and eat it too :) The functionality of dynamic routing, coupled with type-safe urls is already in yesod: Subsites! Unfortunately they are not documented. That's why i personnaly do not use them. I simply cannot figure out how. And yesod-auth can give access to entire subsite, same way as dynamic routing does.
On Monday, April 04, 2011 04:21:20 AM Michael Snoyman wrote:
Hi all,
There's an inherent difference in how Yesod handles routing, by default, and how Happstack/Snap handle routing, by default. (Apologies if I am mistaken in my understanding of the latter.) Yesod is built in with the concept of type-safe URLs. This forms the basis of routing in Yesod: the list of path segments is first converted to a type-safe URL value, and then the appropriate handler is chosen from that. On the other hand, Happstack/Snap both allow you to perform routing directly on the path segments.
What many people don't realize is that it's entirely possible to do segment-based routing in Yesod. I don't recommend the practice in general, since it defeats a lot of the type safety Yesod gives you. However, in some situations it's a necessity. For example, yesod-auth allows arbitrary authentication plugins, which would not mesh up well with type-safe URLs.
The trick to bypassing the type safety is to use multi-pieces. Instead of describing how this is possible, I will merely point to an example: https://gist.github.com/884802
The Yesod.Dynamic module defined there is really a general way to allow Yesod routing based on path segments. Since the question has come up a number of times in the past, I'm curious if people would want this available on hackage. I'm sure a nice set of routing operators would be useful here as well.
Michael
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel