播放2.0.4 Catch-all路线总是命中

bie*_*ior 1 routes playframework playframework-2.0

在我的路由文件的末尾,我放置了一个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/细分.那可能吗?

Sch*_*rdt 6

我重复了它并且与Chromium(谷歌Chrome的核心)有同样的问题,但不是Firefox.

使用Global.java我分析了请求.

public class Global extends GlobalSettings {
    @Override
    public Action onRequest(Http.Request request, Method method) {
        Logger.info("request-path: " + request.path());
        return super.onRequest(request, method);
    }
}
//output:
[info] application - request-path: /favicon.ico
Run Code Online (Sandbox Code Playgroud)

对于每个GET /测试请求,Chromium都会尝试加载favicon.

因此,在conf/routes中包含以下内容:

GET  /favicon.ico   controllers.Assets.at(path="/public", file="favicon.ico")
Run Code Online (Sandbox Code Playgroud)