This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.0.1
Elm module for single page app routing
version 1.0.2
license MIT
native-modules False
elm-version 0.17.0 <= v < 0.18.0
Tag 1.0.2
Committed At 2016-06-06 07:19:31 UTC
elm-lang/core 4.0.0 <= v < 5.0.0 4.0.5

README

elm-router

Install

$ elm-package install poying/elm-router

Example

module Main where


import Result
import String
import Dict exposing (Dict)
import Router exposing ((:~>), (:=>))
import Router.Parameter exposing ((/:), int, string)
import Graphics.Element exposing (show)


type Page
  = Home
  | Article String Int
  | AdminHome
  | NotFound


match =
  Router.match router NotFound


router =
  [ "/" :~> always Home
  , "/user/:uid/article/:aid" :~> always Article /: string "uid" /: int "aid"
  -- nested router
  , "/admin" :=> adminRouter
  ]


adminRouter =
  [ "/" :~> always AdminHome
  ]


main =
  show <|
    case match "/user/poying/article/123" of
      Home -> "Home"
      AdminHome -> "AdminHome"
      Article uid aid -> "Article " ++ uid  ++ " " ++ toString aid
      NotFound -> "NotFound"

License

(The MIT License)

Copyright (c) 2016 Po-Ying Chen poying.me@gmail.com.