{"id":15355170,"url":"https://github.com/sake92/scalajs-router","last_synced_at":"2025-06-11T13:12:31.737Z","repository":{"id":57715058,"uuid":"294210471","full_name":"sake92/scalajs-router","owner":"sake92","description":"ScalaJS frontend router","archived":false,"fork":false,"pushed_at":"2020-12-14T15:21:12.000Z","size":23,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T00:06:39.370Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sake92.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-09T19:32:07.000Z","updated_at":"2024-12-09T19:54:20.000Z","dependencies_parsed_at":"2022-09-02T22:01:25.254Z","dependency_job_id":null,"html_url":"https://github.com/sake92/scalajs-router","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sake92%2Fscalajs-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sake92%2Fscalajs-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sake92%2Fscalajs-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sake92%2Fscalajs-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sake92","download_url":"https://codeload.github.com/sake92/scalajs-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sake92%2Fscalajs-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259271879,"owners_count":22832100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:22:54.537Z","updated_at":"2025-06-11T13:12:31.681Z","avatar_url":"https://github.com/sake92.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scalajs-router [![Maven Central](https://img.shields.io/maven-central/v/ba.sake/scalajs-router_sjs1_2.13.svg?style=flat-square\u0026label=Scala+2.13)](https://mvnrepository.com/artifact/ba.sake/scalajs-router) [![Build Status](https://img.shields.io/travis/sake92/scalajs-router/master.svg?logo=travis\u0026style=flat-square)](https://travis-ci.com/sake92/scalajs-router) \n\nScalaJS frontend router.\n\nIn your HTML add `data-navigate` attribute to nav elements:\n\n```html\n\u003cnav\u003e\n  \u003cbutton data-navigate=\"/home\"\u003eHome\u003c/button\u003e\n  \u003cbutton data-navigate=\"/users/1\"\u003eUser details\u003c/button\u003e\n\u003c/nav\u003e\n```\n\nCreate element where router will show your dynamic content:\n```html\n\u003cdiv id=\"main\"\u003e\u003c/div\u003e\n```\n\nThen specify your routes and bind the router:\n```scala\nval routes: Router.Routes = {\n  case \"/home\"        =\u003e HomeComponent\n  case s\"/users/$id\"  =\u003e UserDetailsComponent(id.toLong)\n  case _              =\u003e NotFoundComponent\n}\n\nRouter(\"main\", routes).init()\n\n// components\nobject HomeComponent extends Component {\n  def asElement: Element = ...\n}\ncase class UserDetailsComponent(userId: Long) extends Component ..\nobject NotFoundComponent extends Component ..\n```\n\n---\nYou can attach a listener when a route changes:\n```scala\nRouter().withListener {\n  case \"/active\"    =\u003e // do something...\n  case \"/other\"     =\u003e \n  case whateverElse =\u003e \n}.init()\n```\n\n---\nWith [`@Route` macro](https://github.com/sake92/stone#route) \nyou can simplify your routes matching to this:\n\n```scala\n@Route class HomeRoute(p1: \"home\")()\n@Route class UserDetailsRoute(p1: \"users\", val userId: Long)()\n\nval routes: Router.Routes = {\n  case HomeRoute()              =\u003e HomeComponent\n  case UserDetailsRoute(userId) =\u003e UserDetailsComponent(userId)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsake92%2Fscalajs-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsake92%2Fscalajs-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsake92%2Fscalajs-router/lists"}