New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rage-route

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rage-route

Tiny, feature lite, super basic client router

latest
Source
npmnpm
Version
3.0.3
Version published
Maintainers
1
Created
Source

rage-route NPM version js-standard-style

Tiny, feature lite, super basic client router

Why rage?

This was built as a very feature light replacement for page.js.

Ships with es6 styled module and commonjs module for your rolling pleasure.

Install

$ npm install --save rage-route

Usage

import { addRoute, addRedirect, route, history } from 'rage-route'
addRoute('/somepage', 'Page Title', (state) => handlePageRoute(state))
addRedirect('/someotherpage', '/somepage')
addRoute('.*', 'Everything Else', (state) => handleDefaultRoute(state))
...
route('/somepage')
...
console.log(history.previous)
console.log(history.current)

API

Add route handler

addRoute(*path, *title, *callback)

  • path [string - required] (ex. '/somepage')
  • title [string - required] (ex. 'Page Title')
  • callback [function - receives state object - required] (ex. (state) => fn(state))

Add redirect from a new path to an existing path

addRedirect(*newPath, *existingPath)

  • newPath [string - required] (ex. '/someotherpage')
  • existingPath [string - required] (ex. '/somepage')

Route to another page, triggering callback set in addRoute

route(*path, *title, *state, *noStore)

  • path [string - required] (ex. '/somepage')
  • title [string - optional] (ex. 'Page Title')
  • state [object - optional] (ex. {foo: 'bar'})
  • noStore [boolean - optional - don't store state in history] (ex. true)

Get array of registered routes

list()

We also expose a history object with the previous and current page

history

  • previous [string] previous page
  • current [string] current page

License

MIT © Andrew Carpenter

Keywords

client

FAQs

Package last updated on 28 Jul 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