2016-12-28 9 views
0

scalajs-reactのルータのドキュメントでは、@japgolly cautions users of the library that starting URLs with '/' slashes requires additional server configurationです。scalajs-reactで遊ぶURL(「#」なし)play app

これまでのところ、私は次のようにプレイroutesファイルにキャッチすべてのルートを記述しようとした、#ずにかなりのURLを許可するには:Application.scala

で一致したインデックスパスで

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

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

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)に自動リダイレクトされています。その他の静的ルートは、Webアプリでクリックすると機能しますが、読み込みに失敗します。

答えて

1

結局のところ、問題はBaseUrl.fromWindowOrigin_/の代わりにBaseUrl.until#を使用していました。これで、すべてのルートが期待通りに機能します。

関連する問題