dillonkearns / elm-pages-v3-beta / UrlPath

Represents the path portion of a URL (not query parameters, fragment, protocol, port, etc.).

This helper lets you combine together path parts without worrying about having too many or too few slashes. These two examples will result in the same URL, even though the first example has trailing and leading slashes, and the second does not.

UrlPath.join [ "/blog/", "/post-1/" ]
    |> UrlPath.toAbsolute
--> "/blog/post-1"

UrlPath.join [ "blog", "post-1" ]
    |> UrlPath.toAbsolute
--> "/blog/post-1"

We can also safely join Strings that include multiple path parts, a single path part per string, or a mix of the two:

UrlPath.join [ "/articles/archive/", "1977", "06", "10", "post-1" ]
    |> UrlPath.toAbsolute
--> "/articles/archive/1977/06/10/post-1"

Creating UrlPaths


type alias UrlPath =
List String

The path portion of the URL, normalized to ensure that path segments are joined with /s in the right places (no doubled up or missing slashes).

join : UrlPath -> UrlPath

Turn a Path to a relative URL.

fromString : String -> UrlPath

Create a UrlPath from a path String.

UrlPath.fromString "blog/post-1/"
    |> UrlPath.toAbsolute
    |> Expect.equal "/blog/post-1"

Turning UrlPaths to String

toAbsolute : UrlPath -> String

Turn a UrlPath to an absolute URL (with no trailing slash).

toRelative : UrlPath -> String

Turn a UrlPath to a relative URL.

toSegments : String -> List String