noredink-ui/styleguide-app/Routes.elm

32 lines
719 B
Elm
Raw Normal View History

2018-02-13 00:32:38 +03:00
module Routes exposing (Route(..), fromLocation)
import ModuleExample exposing (categoryFromString)
import Navigation
import UrlParser as Url exposing ((</>), custom, s, string, top)
type Route
= Doodad String
| Category ModuleExample.Category
| All
route : Url.Parser (Route -> a) a
route =
Url.oneOf
[ Url.map Category (s "category" </> category)
, Url.map Doodad (s "doodad" </> s "Nri" </> string)
, Url.map All top
]
category : Url.Parser (ModuleExample.Category -> a) a
category =
custom "category" categoryFromString
fromLocation : Navigation.Location -> Route
fromLocation location =
Url.parseHash route location
|> Maybe.withDefault All