@arco-tech/mithril-router

Mithril.js router with additional helper functions

Usage no npm install needed!

<script type="module">
  import arcoTechMithrilRouter from 'https://cdn.skypack.dev/@arco-tech/mithril-router';
</script>

README

mithril-router.js

Mithril.js router wrapper with added functionality

Installation

npm i @arco-tech/mithril-router

or

yarn i @arco-tech/mithril-router

Usage

import { Router } from "@arco-tech/mithril-router"

import { HomeScreen } from "./screens/home_screen"
import { PostsScreen } from "./screens/posts_screen"
import { PostScreen } from "./screens/post_screen"

const router = new Router({
  prefix: "",
  routes: [
    { id: "home", path: "", component: HomeScreen },
    { id: "posts", path: "/posts", component: PostsScreen },
    { id: "post", path: "/posts/:id", component: PostScreen },
  ],
})

router.init(document.body) // calls m.route()

router.path("posts")
// "/posts"

router.path("posts", { q: "test", limit: 10 })
// "/posts?q=test&limit=10"

router.path("post", { id: 123, overlay: "update" })
// "/posts/123?overlay=update"

router.route("post", { id: 123 }) // calls m.route.set()