https://github.com/sake92/scalajs-router
ScalaJS frontend router
https://github.com/sake92/scalajs-router
Last synced: about 1 year ago
JSON representation
ScalaJS frontend router
- Host: GitHub
- URL: https://github.com/sake92/scalajs-router
- Owner: sake92
- License: apache-2.0
- Created: 2020-09-09T19:32:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-14T15:21:12.000Z (over 5 years ago)
- Last Synced: 2025-04-15T00:06:39.370Z (over 1 year ago)
- Language: Scala
- Size: 22.5 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# scalajs-router [](https://mvnrepository.com/artifact/ba.sake/scalajs-router) [](https://travis-ci.com/sake92/scalajs-router)
ScalaJS frontend router.
In your HTML add `data-navigate` attribute to nav elements:
```html
Home
User details
```
Create element where router will show your dynamic content:
```html
```
Then specify your routes and bind the router:
```scala
val routes: Router.Routes = {
case "/home" => HomeComponent
case s"/users/$id" => UserDetailsComponent(id.toLong)
case _ => NotFoundComponent
}
Router("main", routes).init()
// components
object HomeComponent extends Component {
def asElement: Element = ...
}
case class UserDetailsComponent(userId: Long) extends Component ..
object NotFoundComponent extends Component ..
```
---
You can attach a listener when a route changes:
```scala
Router().withListener {
case "/active" => // do something...
case "/other" =>
case whateverElse =>
}.init()
```
---
With [`@Route` macro](https://github.com/sake92/stone#route)
you can simplify your routes matching to this:
```scala
@Route class HomeRoute(p1: "home")()
@Route class UserDetailsRoute(p1: "users", val userId: Long)()
val routes: Router.Routes = {
case HomeRoute() => HomeComponent
case UserDetailsRoute(userId) => UserDetailsComponent(userId)
}
```