耶索德全包路线 [英] Yesod catchall route
问题描述
我正在构建一个由两部分组成的yesod应用。其余的api(yesod)和客户端的(angularjs)。
I'm building a yesod app which consists of two parts. The rest api (yesod) and the client side (angularjs).
除了作为REST api之外,yesod还将初始的html发送给客户端以启动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:
配置/路由:
/user GET
/someOtherEntity GET POST
/ HomeR GET --route to send the html
$ b $的路由b
Handler / Home.hs
Handler/Home.hs
getHomeR :: Handler Html
getHomeR = sendFile typeHtml "frontend/build/index.html"
只要第一个网址是www.mydomain.com/, ,但是当我访问www.mydomain / some-angular / route时,我从yesod收到了404。
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.
我已经尝试过:
/#Text HomeR GET
这对于/ my-angular-route正常工作,但在/ my-angular-route / param上中断。我可以添加/#Text /#Text,但是肯定有一种更清洁的方式来处理此问题。
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.
我如何实现某种形式的全程捕获?因此,只要不是与路由匹配的网址,都应该调用getHomeR。
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.
推荐答案
您可以使用多段路由,并且可能需要关闭重叠检查。看起来像这样:
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.
这篇关于耶索德全包路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!