You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@nano-router/router

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nano-router/router

The nano-router

3.2.0
latest
Source
npmnpm
Version published
Weekly downloads
580
279.08%
Maintainers
1
Weekly downloads
 
Created
Source

@nano-router/router - API

A framework agnostic minimalistic router with a focus on named routes.

This package is meant as a basis for creating framework specific routers like the React integration.

Instalation

npm install @nano-router/history @nano-router/router

Usage

Setup the history

import {
  createBrowserHistory,
  createMemoryHistory,
} from "@nano-router/history";

const browserHistory = createBrowserHistory();
// or
const memoryHistory = createMemoryHistory();

Setup your routes

import { Routes, Route } from "@nano-router/router";

const routes = new Routes(
  new Route("posts/new", "/posts/new"),
  new Route("posts/edit", "/posts/:id"),
  new Route("posts", "/posts"),
);

See @nano-router/routes for more information about the route configuration.

Create the router

const router = new Router({ routes, history: browserHistory });

Listen for updates on the router

router.listen(() => {
  // routing has been updated
});

See history.listen(...) for more information.

navigate

router.navigate({ route: "posts/edit", params: { id: 42 } });

Get the current route information

const routeName = router.route;
const { pathname, hash, search, state } = router.location;
const { id } = router.params;

MIT License

Copyright (c) 2020 Sune Simonsen mailto:sune@we-knowhow.dk

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

browser

FAQs

Package last updated on 11 Jun 2025

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