Last active
January 7, 2017 19:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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