New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

router-dom

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

router-dom

A lightweight router for everyone

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
decreased by-2.84%
Maintainers
1
Weekly downloads
 
Created
Source

router-dom

A lightweight router for single-page applications.

  • it helps to reduce the delay between your pages, to minimize browser HTTP requests and enhance your user's web experience.
  • library agnostic.
  • simple: define your routes, start to listen to route changes
  • base support
  • support in all modern browsers.

Installation

With npm:

$ npm i router-dom

or via CDN:

<script type="module">
  import Router from "https://unpkg.com/router-dom";
</script>

Usage

Use the href attribute in order to help quicklink prefetching the resource and use data-href as routing path.

<a href="/">Home</a>
<a href="about.html" data-href="/about">About</a>
<div data-outlet></div>

Dependencies

path-to-regexp: Turn a path string such as '/user/:name' into a regular expression
quicklink: Faster subsequent page-loads by prefetching in-viewport links during idle time
hydro-js: Renders the view. In order to pass state via an anchor element (data attribute), a mapping on the hydro object is needed.

Documentation

Constructor

The router class takes an array with at least one entry. Only the path is mandatory. Either a template or and element will be rendered in your element with attribute data-outlet. The second argument is the optional object options: it can take a general errorHandler.

const router = new Router([
   {
    path: "/",
  },
  {
    path: "/about",
    templateUrl: "/about.html",
    leave: ({ from, to, state, params }) => ...
  },
  {
    path: "/contact/:name",
    element: html`<h2>Drop a message on [...]</h2>`,
    beforeEnter: ({ from, to, state, params }) => ...,
    afterEnter: ({ from, to, state, params }) => ...
  }
]);

go

  • Takes a path, a state object and optional params. Will redirect to the path.

removeRoute

  • Removes a route from the routes array.

addRoute

  • Adds a route object to the routes array.

modifyRoute

  • Replaces a route with a new one.

changeOptions

  • Replaces the router options.

getParams

  • Returns the params as key-value pair.

To Do

  • Add tests
  • Add nested routes

Keywords

FAQs

Package last updated on 15 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc