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

@storeon/router

Package Overview
Dependencies
Maintainers
5
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

  • 0.1.0
  • npm
  • Socket score

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

Storeon Router

Storeon logo by Anton Lovchikov

Storeon Router which solves the problem of routing your application, providing full control over the route.

It size is 635 bytes (minified and gzipped) and uses Size Limit to control size.

Installation

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

Usage

If you want to use the router you should import the router.createRouter from @storeon/router and add this module to createStore.

import createStore from 'storeon'
import router from '@storeon/router'

const store = createStore([
  router.createRouter([
    ['/', () => ({ page: 'home' })],
    ['/blog', () => ({ page: 'blog' })],
    ['/blog/post/*', (id) => ({ page: 'post', id })],
    [
      /^blog\/post\/(\d+)\/(\d+)$/,
      (year, month) => ({ page: 'post', year, month })
    ]
  ])
])

store.on(router.changed, (state, event) => {
  if (!event.match) {
    show404()
    return
  }

  switch (event.match.page) {
    case 'blog':
      showBlog()
      break
      
    case 'post':
      showPost({
        id: event.match.id,
        year: event.match.year,
        month: event.match.month
      })
      break
      
    default:
      showHome()
  }
})

store.dispatch(router.navigate, '/')

API

import router from '@storeon/router'

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

Function router.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.

router.key – key for store.

router.navigate – navigation action.

router.changed – change event of pathname.

Sponsor

Sponsored by Evrone

LICENSE

MIT

FAQs

Package last updated on 22 May 2019

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