npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@navojs/react-router

v1.1.0

Published

React Router integration for Navo — declarative navigation and permission-based routing

Readme

@navojs/react-router

React Router integration for Navo — declarative navigation and permission-based routing.

Installation

npm install @navojs/react-router react-router

Quick Start

1. Define your navigation structure

import { createNavo } from '@navojs/react-router'

const navo = createNavo([
  { id: 'dashboard', label: 'Dashboard', path: '/dashboard' },
  {
    id: 'users',
    label: 'Users',
    path: '/users',
    children: [
      { id: 'user-list', label: 'User List', path: 'list' },
      { id: 'user-detail', label: 'User Detail', path: ':id', affiliated: true },
    ],
  },
  { id: 'settings', label: 'Settings', path: '/settings' },
])

2. Wrap your app with NavoProvider

import { NavoProvider } from '@navojs/react-router'
import { BrowserRouter } from 'react-router'

function App() {
  return (
    <BrowserRouter>
      <NavoProvider navo={navo}>
        <AppRoutes />
      </NavoProvider>
    </BrowserRouter>
  )
}

3. Generate routes from your navo structure

import { generateRoutes } from '@navojs/react-router'
import { useRoutes } from 'react-router'

function AppRoutes() {
  const routes = generateRoutes(navo)
  return useRoutes(routes)
}

Permission Control

import { useCanAccess } from '@navojs/react-router'

function PermissionGate() {
  const onCanAccess = useCanAccess()

  useEffect(() => {
    // Provide your access control logic
    onCanAccess((node) => {
      return userPermissions.includes(node.id)
    })
  }, [])

  return null
}

Hooks

useCanAccess()

Returns the onCanAccess callback for setting up permission checks.

useCanAccessPage()

Returns a boolean indicating whether the current page is authorized. Use this for route guards.

const canAccess = useCanAccessPage()
if (!canAccess) return <UnauthorizedPage />

useMatchedNodes()

Returns the currently active navigation nodes and their IDs — useful for highlighting menus and breadcrumbs.

const { matchedNodes, matchedIds } = useMatchedNodes()
// matchedIds: ['dashboard', 'users', 'user-list']
// matchedNodes: corresponding NavoNode objects

useNavo()

Returns utility functions for working with the navigation tree:

const { nodes, getNodeById, getPathById, hasCanAccess } = useNavo()

// Get all authorized nodes
nodes.forEach(node => console.log(node.label))

// Check access
if (hasCanAccess('settings')) { /* ... */ }

// Get path by id
const path = getPathById('user-list') // '/users/list'

Route Guard (403 / Unauthorized)

Navo controls menu visibility via authenticat, but routes generated by generateRoutes always include all pages. To block unauthorized URL access, use useCanAccessPage:

import { useCanAccessPage } from '@navojs/react-router'
import { Outlet } from 'react-router'

function Layout() {
  const canAccess = useCanAccessPage()

  return (
    <div>
      <Sidebar />
      <main>
        {canAccess ? <Outlet /> : <UnauthorizedPage />}
      </main>
    </div>
  )
}

Design note: Navo intentionally does not ship a built-in 403 component. It provides the primitives (useCanAccessPage, hasCanAccess, useMatchedNodes) and leaves the UI decision to you.

Route Escape Hatch

You can pass native React Router route properties through the route field:

createNavo([
  {
    id: 'home',
    path: '/',
    route: {
      loader: () => fetchData(),
      caseSensitive: true,
      errorElement: <ErrorPage />,
    },
  },
])

API

generateRoutes(navo)

Converts a Navo instance into an array of React Router RouteObjects with automatic index redirects.

NavoProvider

React context provider that holds the Navo instance and authentication state.

NavoRedirect

Internal component that handles automatic redirection to the resolved path (e.g., redirecting /users to /users/list).

License

MIT