1.4.0 • Published 4 years ago

@rootgog/router v1.4.0

Weekly downloads
16
License
ISC
Repository
github
Last release
4 years ago

Router.js

Router.js is a lightweight frontend page router, and its nestable!.

Configure routes and their handlers, when you resonle a route its handler will be executed.

Features

  • Nested routers
  • wildcard path parameters

To Do:

  • named wildcard parameters

Usage

Link the router.js file

<head>
  <script src="//unpkg.com/@rootgog/router"></script>
</head>

Start Configuring routes

//define an account router for use later
let accountRouter = new Router();
accountRouter
  .on(() => {
    setPageContent("account.html");
  })
  .on("edit", () => {
    setPageContent("accountedit.html");
  });

//define the main router
let router = new Router();
router
  .on(() => {
    setPageContent("home.html");
  })
  .on("account", accountRouter)
  .on("post/*/edit", () => {
    setPageContent("editpost.html");
  })
  .notFound(() => {
    setPageContent("404.html");
  });

Redirecting users

This will use the handler that was configured before

Router.sendTo("account");
1.4.0

4 years ago

1.3.0

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago