module Route exposing (Route(..), fromUrl, toUrl) import Url exposing (Url) import Url.Builder import Url.Parser exposing ((), Parser, int, map, oneOf, parse, s, top) type Route = Collection | DeckList | Deck Int parser : Parser (Route -> a) a parser = oneOf [ map Collection top , map Collection (s "collection") , map DeckList (s "decks") , map Deck (s "decks" int) ] toUrl : Route -> String toUrl route = case route of Collection -> Url.Builder.absolute [ "collection" ] [] DeckList -> Url.Builder.absolute [ "decks" ] [] Deck deckId -> Url.Builder.absolute [ "decks", String.fromInt deckId ] [] fromUrl : Url.Url -> Maybe Route fromUrl url = parse parser url