RedirectUrl instances for subsites

17 views
Skip to first unread message

James Parker

unread,
Oct 20, 2020, 8:32:36 AM10/20/20
to Yesod Web Framework

Hi,

I have multiple subsites that I'm currently upgrading to Yesod 1.6. It looks like I need to define `RedirectUrl` instances for the subsites since the subsites have redirects (ex `redirect MySubsitePageR`). I was attempting to define the instance once using `getRouteToParent`, but get ambiguity check errors (probably due to the type families not being injective). Is there a way to define a general `RedirectUrl` for all subsites?

instance (SubHandlerSite m ~ app, HandlerSite m ~ master) => RedirectUrl master (Route app) where
    toTextUrl r = do
      f <- getRouteToParent
      toTextUrl $ f r

Thanks,

James

Michael Snoyman

unread,
Oct 20, 2020, 8:42:23 AM10/20/20
to yeso...@googlegroups.com
I've never done it this way, since it precludes having multiple copies of the same subsite in a single application. I've always explicitly added the appropriate master site route data constructor around the subsite route I'm trying to redirect to.

--
You received this message because you are subscribed to the Google Groups "Yesod Web Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yesodweb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/yesodweb/1be57680-d6eb-42d7-8b6d-b3b89b081a21n%40googlegroups.com.

James Parker

unread,
Oct 20, 2020, 11:24:26 PM10/20/20
to Yesod Web Framework
Ah interesting. I never considered having multiple copies of the same subsite.

Is there a way for the parent site not to have to define a `RedirectUrl` instance for each subsite? I'm trying to redirect to a route within the same subsite. I currently have something like the following:

getMySubsiteHandlerR :: SubHandlerFor MySubsite master Html
getMySubsiteHandlerR = redirect MySubsitePageR

Michael Snoyman

unread,
Oct 21, 2020, 3:39:59 AM10/21/20
to yeso...@googlegroups.com
That's what I meant by the data constructor from the master site. If you have a routes file with something like:

/foo FooR Foo getFoo

And a Foo subsite with a route BarR, you can use `redirect $ FooR BarR`.

Reply all
Reply to author
Forward
0 new messages