Socket
Socket
Sign inDemoInstall

max-router

Package Overview
Dependencies
12
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    max-router

Opinionated browser routing configuration


Version published
Weekly downloads
0
Maintainers
1
Install size
521 kB
Created
Weekly downloads
 

Readme

Source

max-router

An opinionated browser routing configuration. Basically a wrapper around 2 libraries History and Url Mapper. The purpose being to provide a slightly simpler API for a common use case but without any real flexibility.

Installation

With npm:

> npm install --save-dev max-router

Or yarn:

> yarn add -D max-router

Usage

import * as router from 'max-router'

router.route('/badger/:id', async ({ id }) => {
    const badger = await fetch(`example.com/badger/${id}`)
    // Render badger page...
})

router.onMissing(async path => {
    // Render 404
})

router.onError(async error => {
    // Render 500
})

// Listen for changes to the url (also immediately invokes for current url)
router.listen({ catchUnhandledErrors: true }, async location => {
    // Do middleware type stuff, like authentication...

    // Invoke the router
    router.onLocationChange(location)
})

// If you want to navigate somewhere
router.go('/badger/1')

The catchUnhandledErrors option will set window.onerror and window.onunhandledrejection to call the router's onError, so that unhandled errors can display the 500 page.

Keywords

FAQs

Last updated on 15 Jul 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc