• Stars
    star
    4
  • Rank 3,255,476 (Top 65 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated over 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
104
star
2

nand2tetris

Nand2Tetris course solutions
Scala
61
star
3

sharaf

Minimalistic Scala 3 web framework
Scala
29
star
4

notes

My book notes, tutorials sketches and stuff
HTML
26
star
5

sbt-hepek

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

writing-an-interpreter

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

squery

Simple SQL queries in Scala 3
Scala
8
star
8

kalem

Scalafix rules for generating Withers
Scala
6
star
9

hepek-examples

Self-contained examples of using hepek
Shell
6
star
10

PlayGuiceExample

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

tupson

Stupid simple Scala 3 library for writing and reading JSON
Scala
5
star
12

sake-ba-source

Source code of sake.ba
Scala
5
star
13

sharaf-petclinic

A PetClinic web app based on sharaf, hepek, and squery
Scala
4
star
14

cakum-pakum

Spring REST starter
Java
4
star
15

hepek-classycle

Classycle ressurection
Java
4
star
16

RxTags

Simple, reactive UIs in ScalaJS
Scala
4
star
17

Scalarizmi

Algorithms and data structures, in Scala
Scala
4
star
18

stone

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

hepek-starter

Starter template for static blog with Hepek
Shell
4
star
20

causality

Event driven CQRS example
Java
4
star
21

scala-spec-hepek

Scala specification written with hepek
Scala
3
star
22

mimdex

Search. Memes.
JavaScript
2
star
23

hepek-cask-example

Combine Cask with Hepek
Shell
2
star
24

playful-scala

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

rpnhma

JavaScript
2
star
26

mill-hepek

Mill plugin for rendering Scala objects to files
Scala
2
star
27

fp4noobs

FP for beginners
Scala
2
star
28

mill-scala-hello.g8

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

hepek-play-example

Example of using Hepek with Play
Scala
2
star
30

hepek-kt

Hepek for Kotlin
Kotlin
2
star
31

hepek-zio-example

Scala
2
star
32

hepek-http4s-example

Example of using Hepek with Http4s
Scala
2
star
33

sharaf-fullstack.g8

Giter8 template for a Sharaf fullstack web app
Scala
2
star
34

mill-scala3-library-starter.g8

Giter8 template for a Scala 3 library with Mill
Shell
2
star
35

spring-session-example

Example of using spring-session project
Java
1
star
36

mill-powershell-completion

Basic TAB completion for Mill in PowerShell
PowerShell
1
star
37

PlayBootstrap

Play, Bootstrap, forms
Scala
1
star
38

Win32NamedPipe

Java
1
star
39

java-amber

Code from my presentation on Amber project
Java
1
star
40

sake-ba-blog-source

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

sharaf-todo-backend

Shell
1
star
42

hepek-core

The core of hepek project
Java
1
star
43

capture-treasure-game

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

scala-guice

Guice examples with Scala
Scala
1
star
45

RxTags-Starter

RxTags starter template
Scala
1
star
46

sake92

1
star
47

spring-boot-mill

Shell
1
star
48

yugioh-abridged-calculator

yugioh abridged calculator
JavaScript
1
star