Skip to content

Instantly share code, notes, and snippets.

@nojaf
Last active December 2, 2016 12:41
Show Gist options
  • Save nojaf/f7a303ded62dcd0c12009953dc60f1bf to your computer and use it in GitHub Desktop.
Save nojaf/f7a303ded62dcd0c12009953dc60f1bf to your computer and use it in GitHub Desktop.
import Dict exposing (Dict)
type Page
= NotFound
| LeaderBoardPage
| LoginPage
| RunnerPage
routes : Dict String Page
routes =
Dict.fromList [("#/", LeaderBoardPage)
,("", LeaderBoardPage)
,("#/login", LoginPage)
,("#/runner", RunnerPage)
,("#notfound", NotFound)]
hashToPage : String -> Page
hashToPage hash =
Dict.get hash routes
|> Maybe.withDefault NotFound
pageToHash : Page -> String
pageToHash page =
Dict.toList routes
|> List.filter (\(hash, p) -> p == page)
|> List.head
|> Maybe.withDefault ("#notfound", NotFound)
|> Tuple.first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment