Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@storeon/router

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storeon/router

Storeon module for URL routing

  • 2.0.0
  • npm
  • Socket score

Version published
Weekly downloads
83
increased by1.22%
Maintainers
2
Weekly downloads
 
Created
Source

Storeon Router

Storeon logo by Anton Lovchikov

Storeon Router solves the problems of routing while seamlessly providing full control.

Its size is 577 bytes (minified and gzipped) and uses Size Limit to control size.

import { createStoreon } from 'storeon'
import { createRouter, routerChanged, routerKey } from '@storeon/router'

const store = createStoreon([
  createRouter([
    ['/', () => ({ page: 'home' })],
    ['/blog', () => ({ page: 'blog' })],
    ['/blog/post/*', (id) => ({ page: 'post', id })],

    [
      /^blog\/post\/(\d+)\/(\d+)$/,
      (year, month) => ({ page: 'post', year, month })
    ]
  ])
])

setData(store.get()[routerKey])

store.on(routerChanged, function (_, data) {
  setData(data)
})

function setData (data) {
  document
    .querySelector('.data')
    .innerText = JSON.stringify(data)
}
Sponsored by Evrone

Installation

npm install @storeon/router
# or
yarn add @storeon/router

Examples

API

import { createRouter } from '@storeon/router'

const moduleRouter = createRouter([
  [path, callback]
])

Function createRouter could have options:

  • path: path name can be a string or RegExp.
  • callback: the callback function must return an object with parameters for this path.

routerKey – key for store.

routerNavigate – navigation action.

routerChanged – change event of pathname.

Add data-ignore-router attribute to the link so that the router ignores it.

FAQs

Package last updated on 11 Oct 2020

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