Yesod catchall route

て烟熏妆下的殇ゞ 提交于 2019-12-11 04:04:55

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/31011940/yesod-catchall-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!