2019-02-01 20:25:58 +00:00
|
|
|
---
|
2019-03-23 04:52:03 +00:00
|
|
|
layout: docs
|
2019-02-01 20:25:58 +00:00
|
|
|
title: "Outwatch Router"
|
|
|
|
section: "home"
|
|
|
|
---
|
|
|
|
|
2019-02-01 16:21:07 +00:00
|
|
|
Outwatch Router
|
|
|
|
===
|
|
|
|
|
2019-02-04 05:02:45 +00:00
|
|
|
Route creation strategy was mostly taken from Http4s. To create paths and map them to pages:
|
|
|
|
|
2019-02-01 16:21:07 +00:00
|
|
|
```scala mdoc
|
2019-02-04 05:02:45 +00:00
|
|
|
import outwatch.router._
|
2019-02-01 16:21:07 +00:00
|
|
|
|
|
|
|
sealed abstract class Page
|
|
|
|
case class RootPage() extends Page
|
|
|
|
case class Login() extends Page
|
|
|
|
case class Register() extends Page
|
|
|
|
case class Profile(userId: String) extends Page
|
|
|
|
case class NotFound() extends Page
|
|
|
|
|
2019-02-04 05:02:45 +00:00
|
|
|
def routes: PartialFunction[Path, Page] = {
|
|
|
|
case Root => RootPage()
|
|
|
|
case Root / "login" => Login()
|
|
|
|
case Root / "register" => Register()
|
|
|
|
case Root / "profile" / userId => Profile(userId)
|
|
|
|
case _ => NotFound()
|
2019-02-01 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 05:02:45 +00:00
|
|
|
routes(Root)
|
|
|
|
routes(Root / "login")
|
|
|
|
routes(Root / "profile" / "saopa98f")
|
2019-02-01 16:21:07 +00:00
|
|
|
|
2019-02-04 05:02:45 +00:00
|
|
|
routes(Path("/profile/asd"))
|
|
|
|
routes(Path("/apsinoasn"))
|
2019-02-01 16:21:07 +00:00
|
|
|
```
|