播放2.0.4万能路线总会命中 [英] Play 2.0.4 Catch-all route always hits
问题描述
在我的路由文件的末尾,我放置了一条全部捕获的路由以捕获以前未捕获的请求,并将其传递到我自己的路由器(以进行进一步处理):
At the end of my routes file I put a catch-all route to catch requests which wasn't catch previously and pass it to my own router (for further processing):
GET /*nameUrl controllers.Application.router(nameUrl: String)
当然,在那条线之前还有很多其他路线.对我来说,最大的惊喜是,即使同时也击中了以前的路线,每次都将捕获全部捕获,因此,如果我打开地址domain.tld/test
,它将在控制台Test action hit!
和Custom router hit!
中向我显示两个日志.有一个简化的示例:
of course there are many other routes BEFORE that line. The big surprise for me is that the catch-all is hitten every time, even if previous route is hitten as well, so if I'm opening address domain.tld/test
it displays me both logs in the console Test action hit!
AND Custom router hit!
. There is a simplified sample:
public static Result test() {
Logger.debug("Test action hit!");
return ok();
}
public static Result router(String nameUrl) {
Logger.debug("Custom router hit!");
return ok();
}
路线(按此顺序)
GET /test controllers.Application.test
GET /*nameUrl controllers.Application.router(nameUrl: String)
我想得到什么:
我想使用路由器来获取文章的网址,即domain.tld/category_1/article_title
之前没有任何前缀,当然,如果我将所有内容更改为稳定的内容,就不会再出现两次匹配了:
I want to get url's for articles with my router ie domain.tld/category_1/article_title
without any prefix before it, of course if I change catch all to something stable it won't get double hits anymore:
GET /news/*nameUrl controllers.Application.router(nameUrl: String)
domain.tld/news/category_1/article_title
但是我真的想避免/news/
段.有可能吗?
however I really want to avoid /news/
segment. Is that possible?
推荐答案
我重复了此步骤,但Chromium(Google Chrome的核心)却遇到了同样的问题,但Firefox却没有.
I repeated it and had the same problem with Chromium (core of Google Chrome), but not with Firefox.
我使用Global.java分析了请求.
With Global.java I analyzed the request.
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
对于每个GET/test请求,Chromium都会尝试加载收藏夹图标.
For every GET /test request Chromium tries to load the favicon.
因此,请在conf/routes中添加以下内容:
So, include the following in conf/routes:
GET /favicon.ico controllers.Assets.at(path="/public", file="favicon.ico")
这篇关于播放2.0.4万能路线总会命中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!