Router Module

Module to Control which Element to insert based on the Path

Router is a browser module that aims to let implementations change elements inside a wrapper element in response to path change events.

Installing

Using NPM:


npm i @modnes/router

          

Downloading package:

Usage

This package is intended to be used as an ES module.


import Router from 'node_modules/@modnes/router/router.js'

          

The Router must receive an HTML Element from DOM and optionally an Array of route objects.

Working Example

This is a working example using Router in a custom element:

Methods

Data Controller provides some useful methods: addRoute(), getParams() and Router.goTo().

addRoute

The addRoute() method can be used inside a proccess to dynamically add new routes to the Router.

getParams

The getParams() returns an object with URI parameters as properties.

Router.goTo

Router.goTo() is a static method that can be used to navigate to a new path.

Router Anchor

The Router package also provides a custom element module to extend the native a HTML tag. It implements the Router.goTo() static method.