我試圖在我的應用程序中建立一些相當複雜的麪包屑功能,其中多個頁面可能鏈接到一個詳細信息頁面,但我只想顯示詳細信息頁面的麪包屑,如果通過特定路線到達頁面。如何檢查URL是否與Lift中現有的Loc匹配?
在我的用例中,用戶會轉到搜索頁面並鍵入搜索字符串。表單在當前頁面上使用「get」方法爲用戶呈現包含一些項目的搜索結果。用戶選擇一個項目以深入其詳細信息頁面。在詳細信息頁面上,我檢查S.referer
,發現它是一個字符串:http://localhost:8080/myapp/search?q=Query+Data+Here
。
有沒有什麼辦法可以採取Search
頁面Loc並測試上面的String URL是否與它匹配?現在我正在執行此檢查,只需在引用字符串上運行一個包含並根據結果執行行爲。
這是我目前的執行:
/**
* List of valid pages to use for generating the page breadcrumbs.
*/
private def validParentLocations = Seq("Search", "Browse")
/**
* If the referer to this page is one of the valid parent locations,
* then find the a tag with the "prev" id and route it to the referer.
*
* If the referer to this page is not in the list or empty, do not
* display the breadcrumb component.
*/
def breadcrumb = {
S.referer match {
case Full(reference) =>
validParentLocations.find(s => reference.contains(s"myapp/${s.toLowerCase}")).map(parent =>
"#prev *" #> parent &
"#prev [href]" #> reference
).getOrElse(ClearNodes)
case _ => ClearNodes
}
}
正如你所看到的,我希望能更換validParentLocations
是祿的,而不是如果我修改頁面的定義在Boot
這可能會破壞脆弱的弦。有沒有辦法基本上說myPageLoc.checkIfUrlMatches(string: String): Boolean
或我失蹤的匹配模式?有沒有更優雅的方式來使用Lift中的現有功能來完成此操作?