krisajenkins/elm-exts/9.4.0

NOTE: this package is not compatible with Elm 0.19.1

Exts.Routing

An experimental routing library.

Note: When this ceases to be experimental, it will probably be split into its own package.

matchRoutes : List (Route a) -> String -> Maybe a

Given a list of routes, find the first that matches the prefix string. Pass the remainer of the string to the route function to get a result.

Example:

type View
  = BlogPost String
  | FrontPage

routes : List (String, String -> Maybe View)
routes = [("blogpost/", Just << BlogPost)
         ,("", always (Just FrontPage))]

> matchRoutes routes "blogpost/hello"
  => Just (BlogPost "hello")
type alias Route a =
( String, String -> Maybe a )

A route is a pair of (the string prefix to match on, a function that turns the suffix into the type you're parsing for.