2015-04-23 53 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

相關問題