2015-04-23 55 views
1

我正在使用与Scala一起玩2。我想定义一个路由器规则,使任何错误的URL被重定向到根:如何在Play2中使用通配符定义url路径?

# Home page 
GET /       controllers.Application.index(ignore="") 

# global fall over 
GET  /*ignore     controllers.Application.index(ignore) 

这是丑陋的,我必须定义一个无用的参数,以满足语法...任何想法如何删除ignore参数?

回答

6

创建您app目录扩展GlobalSettings对象:

import play.api.GlobalSettings 
import play.api.mvc._ 
import play.api.mvc.Results._ 
import scala.concurrent.Future 

object Global extends GlobalSettings{ 
    override def onHandlerNotFound(request: RequestHeader) = { 
    Future.successful(Redirect("/")) 
    } 
} 

//routes 
GET /       controllers.Application.index() 

文档:https://www.playframework.com/documentation/2.3.x/ScalaGlobal

+1

良好的渔获,谢谢,我已经编辑答案。 – Infinity

+0

把它当作错误处理...为什么我不这样想。谢谢! – davidshen84

相关问题