Laminar Frontroute

Sourcecode on Github: https://github.com/tulz-app/frontroute

Install dependencies

import org.scalajs.linker.interface.ModuleSplitStyle
 
lazy val myapp = project
  .in(file("."))
  .enablePlugins(ScalaJSPlugin)
  .settings(
    scalaVersion := "3.3.3",
    scalaJSUseMainModuleInitializer := true,
    scalaJSLinkerConfig ~= {
      _.withModuleKind(ModuleKind.ESModule)
        .withModuleSplitStyle(
          ModuleSplitStyle.SmallModulesFor(List("myapp"))
        )
    },
    libraryDependencies ++= Seq(
      "org.scala-js" %%% "scalajs-dom" % "2.4.0",
      "com.raquo" %%% "laminar" % "16.0.0",
      "io.frontroute" %%% "frontroute" % "0.18.2"
    )
  )

Usage

App.scala
package myapp
 
import org.scalajs.dom
 
import com.raquo.laminar.api.L.{*, given}
import frontroute.*
 
val myApp = routes(
  div(
    pathEnd {
      div("Home page.")
    },
    (path("about")) {
      div("About page")
    },
    (noneMatched & extractUnmatchedPath) { unmatched =>
      div(
        div("Not Found"),
        div(
          span("Not found path:"),
          span(unmatched.mkString("/", "/", ""))
        )
      )
    }
  )
)
 
@main
def MyApp(): Unit =
  lazy val root = dom.document.querySelector("#app")
  renderOnDomContentLoaded(root, myApp)
Last Update: 08:28 - 26 April 2024

On this page