我试图在我的应用程序中建立一些相当复杂的面包屑功能,其中多个页面可能链接到一个详细信息页面,但我只想显示详细信息页面的面包屑,如果通过特定路线到达页面。如何检查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中的现有功能来完成此操作?