在我的路由文件的末尾,我放置了一个catch-all路由来捕获之前未捕获的请求并将其传递给我自己的路由器(以进行进一步处理):
GET /*nameUrl controllers.Application.router(nameUrl: String)
Run Code Online (Sandbox Code Playgroud)
当然,在该行之前还有许多其他路线.对我来说最大的惊喜是,包罗万象的是hitten每一次,即使先前的路线hitten一样,所以如果我打开地址domain.tld/test则显示了我两个日志在控制台Test action hit!和 Custom router hit!.有一个简化的样本:
public static Result test() {
Logger.debug("Test action hit!");
return ok();
}
public static Result router(String nameUrl) {
Logger.debug("Custom router hit!");
return ok();
}
Run Code Online (Sandbox Code Playgroud)
路线(按此顺序)
GET /test controllers.Application.test
GET /*nameUrl controllers.Application.router(nameUrl: String)
Run Code Online (Sandbox Code Playgroud)
我想得到什么:
我想用我的路由器获取文章的url,即domain.tld/category_1/article_title之前没有任何前缀,当然如果我将catch全部更改为稳定的东西,它将不再获得双击:
GET /news/*nameUrl controllers.Application.router(nameUrl: String)
domain.tld/news/category_1/article_title
Run Code Online (Sandbox Code Playgroud)
但是我真的想避免/news/细分.那可能吗?