diff --git a/src/Internal/ApiRoute.elm b/src/Internal/ApiRoute.elm index 35fdc281..88f69bac 100644 --- a/src/Internal/ApiRoute.elm +++ b/src/Internal/ApiRoute.elm @@ -66,6 +66,7 @@ pathToMatches path (ApiRouteBuilder _ pattern _ _ _) = path |> List.concatMap .submatches |> List.filterMap identity + |> List.reverse {-| -} @@ -88,6 +89,7 @@ tryMatch path (ApiRouteBuilder _ pattern handler _ _) = path |> List.concatMap .submatches |> List.filterMap identity + |> List.reverse in handler matches |> Just diff --git a/tests/ApiRouteTests.elm b/tests/ApiRouteTests.elm index a7a21bae..a64a7e2d 100644 --- a/tests/ApiRouteTests.elm +++ b/tests/ApiRouteTests.elm @@ -76,6 +76,38 @@ all = [ "users/100.json" , "users/101.json" ] + , test "matches with two dynamic segments" <| + \() -> + succeed + (\author name -> + author ++ " - " ++ name + ) + |> literal "package" + |> slash + |> capture + |> slash + |> capture + |> tryMatch "package/dillonkearns/elm-pages" + |> Expect.equal (Just "dillonkearns - elm-pages") + , test "routes with two dynamic segments" <| + \() -> + succeed + (\author name -> + author ++ " - " ++ name + ) + |> literal "package" + |> slash + |> capture + |> slash + |> capture + |> withRoutes + (\constructor -> + [ constructor "dillonkearns" "elm-pages" + ] + ) + |> Expect.equal + [ "package/dillonkearns/elm-pages" + ] , describe "toPattern" [ test "no dynamic segments" <| \() ->