• Stars
    star
    4
  • Rank 3,062,113 (Top 65 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ScalaJS frontend router

scalajs-router Maven Central Build Status

ScalaJS frontend router.

In your HTML add data-navigate attribute to nav elements:

<nav>
  <button data-navigate="/home">Home</button>
  <button data-navigate="/users/1">User details</button>
</nav>

Create element where router will show your dynamic content:

<div id="main"></div>

Then specify your routes and bind the router:

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:

Router().withListener {
  case "/active"    => // do something...
  case "/other"     => 
  case whateverElse => 
}.init()

With @Route macro you can simplify your routes matching to this:

@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)
}

More Repositories

1

hepek

Typesafe HTML templates and static site generator in pure Scala
Scala
96
star
2

nand2tetris

Nand2Tetris course solutions
Scala
58
star
3

notes

My book notes, tutorials sketches and stuff
HTML
25
star
4

sbt-hepek

Sbt plugin for rendering Scala objects to files. And more!
Scala
21
star
5

sharaf

Minimalistic Scala 3 web framework
Scala
19
star
6

writing-an-interpreter

Writing a simple interpreter in ANTLR4 and by hand in Scala
Java
12
star
7

kalem

Scalafix rules for generating Withers
Scala
6
star
8

hepek-examples

Self-contained examples of using hepek
Shell
6
star
9

PlayGuiceExample

PlayFramework, Scala, Guice, DI, Testing, ScalaTest
Scala
6
star
10

squery

Simple SQL queries in Scala 3
Scala
5
star
11

sake-ba-source

Source code of sake.ba
Scala
5
star
12

cakum-pakum

Spring REST starter
Java
4
star
13

hepek-classycle

Classycle ressurection
Java
4
star
14

causality

Event driven CQRS example
Java
4
star
15

RxTags

Simple, reactive UIs in ScalaJS
Scala
4
star
16

Scalarizmi

Algorithms and data structures, in Scala
Scala
4
star
17

stone

URL (de)construct. Withers.
Scala
4
star
18

hepek-starter

Starter template for static blog with Hepek
Shell
4
star
19

hepek-starter.g8

Hepek giter8 template
Scala
3
star
20

tupson

Stupid simple Scala 3 library for writing and reading JSON
Scala
3
star
21

scala-spec-hepek

Scala specification written with hepek
Scala
3
star
22

cask-hepek

Combine Cask with Hepek
Scala
2
star
23

playful-scala

Full-stack Scala with Play, ScalaJS, Hepek templates, Stone routes
Scala
2
star
24

rpnhma

JavaScript
2
star
25

mimdex

Search. Memes.
JavaScript
2
star
26

fp4noobs

FP for beginners
Scala
2
star
27

mill-scala-hello.g8

Giter8 template for Scala hello world with Mill
Scala
2
star
28

hepek-kt

Hepek for Kotlin
Kotlin
2
star
29

play-hepek-example

Example of using Hepek with Play
Scala
2
star
30

spring-session-example

Example of using spring-session project
Java
1
star
31

Win32NamedPipe

Java
1
star
32

mill-powershell-completion

Basic TAB completion for Mill in PowerShell
PowerShell
1
star
33

sake-ba-blog-source

Source code of blog.sake.ba
Scala
1
star
34

PlayBootstrap

Play, Bootstrap, forms
Scala
1
star
35

java-amber

Code from my presentation on Amber project
Java
1
star
36

sharaf-todo-backend

Shell
1
star
37

yugioh-abridged-calculator

yugioh abridged calculator
JavaScript
1
star
38

mill-hepek

Mill plugin for rendering Scala objects to files
Scala
1
star
39

sharaf-petclinic

A PetClinic web app based on sharaf, hepek, and squery
Scala
1
star
40

hepek-core

The core of hepek project
Java
1
star
41

capture-treasure-game

Self-playing "capture the treasure" game
Java
1
star
42

scala-guice

Guice examples with Scala
Scala
1
star
43

RxTags-Starter

RxTags starter template
Scala
1
star
44

spring-boot-mill

Shell
1
star