Skip to content

Instantly share code, notes, and snippets.

@sabine
Last active January 7, 2017 19:28
Show Gist options
  • Save sabine/1462f9586658c911bad3a5ab88e0c524 to your computer and use it in GitHub Desktop.
Save sabine/1462f9586658c911bad3a5ab88e0c524 to your computer and use it in GitHub Desktop.
Example of Nested Routes (with parameters) in Bogdanp/elm-route 4.0.0 and Elm 0.18
module Routes exposing (..)
import Navigation exposing (Location)
import Route exposing (..)
import Combine exposing ((<$),(*>),(<$>))
import Combine.Num
type Sitemap
= ProfileR String Profile
| NotFoundR
type Profile
= AboutMe
| Projects
| Project Int
show : Profile -> String
show profile =
case profile of
AboutMe ->
""
Projects ->
"projects"
Project i ->
"project/" ++ Basics.toString i
profile : Combine.Parser s Profile
profile =
Combine.choice
[
-- beware! the order is very important here and one wrong step may mean that the route is never found!
, Project <$> (Combine.string "project/" *> Combine.Num.int)
, Projects <$ Combine.string "projects"
, AboutMe <$ Combine.string ""
]
profileR =
ProfileR := static "people" </> string </> custom profile
sitemap =
router [ profileR ]
toString : Sitemap -> String
toString r =
case r of
ProfileR username p ->
reverse profileR [ username, show p ]
NotFoundR ->
Debug.crash "cannot render NotFound"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment