Richard Deurwaarder
Richard Deurwaarder

Reputation: 2040

Yesod catchall route

I'm building a yesod app which consists of two parts. The rest api (yesod) and the client side (angularjs).

Besides being a rest api, yesod also send the initial html to the client to start up angularjs. I have it working like this:

config/routes:

/user GET
/someOtherEntity GET POST
/ HomeR GET --route to send the html

Handler/Home.hs

getHomeR :: Handler Html                                                                            
getHomeR = sendFile typeHtml "frontend/build/index.html" 

As long as the first url is www.mydomain.com/ this works fine, but when I go to www.mydomain/some-angular/route I get a 404 from yesod.

I've tried this:

/#Text HomeR GET

This works fine for /my-angular-route, but breaks on /my-angular-route/param. I could add /#Text/#Text I suppose, but surely there's a cleaner way of handling this.

How can I implement some sort of catch all route? So whenever it's not an url which matches a route, it should just call getHomeR.

Upvotes: 2

Views: 173

Answers (1)

Michael Snoyman
Michael Snoyman

Reputation: 31345

You can use multi-piece routes, and will likely need overlap checking turned off. This would look like:

!/*Texts HomeR GET

For more information, see the routing chapter of the Yesod book.

Upvotes: 4

Related Questions