2017-07-17 09:25:57 +00:00
|
|
|
module Routing exposing (..)
|
|
|
|
|
|
|
|
-- Local modules
|
|
|
|
|
2017-07-17 14:05:38 +00:00
|
|
|
import Models exposing (Route(..))
|
2017-07-17 09:25:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- External modules
|
|
|
|
|
|
|
|
import Navigation exposing (Location)
|
2017-07-17 14:05:38 +00:00
|
|
|
import UrlParser exposing (Parser, (</>), oneOf, map, top, s, string, parseHash)
|
2017-07-17 09:25:57 +00:00
|
|
|
|
|
|
|
|
2017-07-17 14:05:38 +00:00
|
|
|
matchers : Parser (Route -> a) a
|
2017-07-17 09:25:57 +00:00
|
|
|
matchers =
|
2017-07-17 14:05:38 +00:00
|
|
|
oneOf
|
|
|
|
[ map OverviewRoute top
|
|
|
|
, map DayRoute (s "day" </> string)
|
|
|
|
, map EventRoute (s "event" </> string)
|
2017-07-17 09:25:57 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
parseLocation : Location -> Route
|
|
|
|
parseLocation location =
|
2017-07-17 14:05:38 +00:00
|
|
|
case parseHash matchers location of
|
2017-07-17 09:25:57 +00:00
|
|
|
Just route ->
|
|
|
|
route
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
NotFoundRoute
|