2016-12-28 60 views
0

scalajs-react路由器的文檔中,@ japgolly cautions users of the library that starting URLs with '/' slashes requires additional server configurationscalajs上的漂亮網址(無'#')反應播放應用

爲了讓漂亮的URL,而不#,到目前爲止,我試着寫一個包羅萬象的路線在播放routes文件類似如下:

# Home page 
GET /  com.xyz.controllers.Application.index(path: String = "") 

... 
# Catch-all route 
GET  /*path  com.xyz.controllers.Application.index(path: String) 

與匹配指數路徑Application.scala

def index(path: String = "") = Action { 
    Ok(views.html.index("Title")) 
} 

和最後的路由在前端使用RouterConfigDsl宣稱:

def create = Router(BaseUrl.until_#, RouterConfigDsl[Loc].buildConfig { dsl => 
    import dsl._ 

    (emptyRule 
    | staticRoute(root, DashboardLoc)     ~> render(filler("Dashboard")) 
    | staticRoute("purchase-orders", PurchaseOrdersLoc) ~> render(filler("Purchase Orders")) 
    | staticRoute("dashboard", DashboardLoc)   ~> render(filler("Dashboard")) 
    | staticRoute("items", ItemsLoc)     ~> render(ItemGallery()) 
    | staticRoute("customers", CustomersLoc)   ~> render(filler("Customers")) 
    | staticRoute("sales-orders", SalesOrdersLoc)  ~> render(filler("Sales Orders")) 
    | staticRoute("preorders", PreordersLoc)   ~> render(filler("Pre-orders")) 
    ).notFound(redirectToPage(DashboardLoc)(Redirect.Replace)) 
    .setTitle(l => s"XYZ | ${l.name}") 
}.renderWith(layout)) 

本地運行,我有應用程序自動重定向到DashboardLoclocalhost:9000/dashboard和其他靜態路由在網絡應用程序中點擊它們時工作,但重新加載時失敗。

回答

1

事實證明,問題畢竟是使用BaseUrl.until#而不是BaseUrl.fromWindowOrigin_/。現在所有的路線都按預期工作。