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

slim-react-router

v0.6.0

Published

A lightweight alternative to React Router with familiar API - BrowserRouter, HashRouter, Route, Switch, Link, and hooks

Downloads

163

Readme

Features

  • Super small (~1.8KiB minzipped)
  • Zero dependencies
  • Familiar API if you've used React Router (though not a 1:1 match)
  • TypeScript support
  • Browser-based and hash-based routing
  • All the essentials: routes, links, navigation, hooks, etc.

Installation

npm install slim-react-router

Usage

import {
  BrowserRouter,
  Route,
  Switch,
  Link,
  useParams,
} from 'slim-react-router'

function App() {
  return (
    <BrowserRouter>
      <nav>
        <Link to="/">Home</Link>
        <Link to="/about">About</Link>
      </nav>

      <Switch>
        <Route path="/" exact element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route path="/user/:id" element={<User />} />
      </Switch>
    </BrowserRouter>
  )
}

function User() {
  const { id } = useParams()
  return <div>User {id}</div>
}

Components

  • <BrowserRouter> - Router using HTML5 history API
  • <HashRouter> - Router using URL hash
  • <Route> - Renders component when path matches. Supports path, exact, element, component, or render props
  • <Switch> / <Routes> (alias) - Renders first matching route
  • <Link> - Navigation link
  • <NavLink> - Link with active state styling. Supports activeClassName and activeStyle
  • <Navigate> - Declarative navigation component for redirects

Hooks

  • useRouter() - Access router context (history + location)
  • useHistory() - Access history object (push, replace, go, etc.)
  • useLocation() - Get current location (pathname, search, hash, state)
  • useNavigate() - Navigate programmatically
  • useParams() - Get URL parameters from dynamic routes
  • useRouteMatch(path?, exact?) - Check if path matches current route
  • useSearchParams() - Get and set query string parameters

Hooks

useNavigate()

Navigate programmatically to different routes:

import { useNavigate } from 'slim-react-router'

function LoginButton() {
  const navigate = useNavigate()

  const handleLogin = async () => {
    await loginUser()
    // Navigate to dashboard
    navigate('/dashboard')

    // Navigate with state
    navigate('/dashboard', { state: { from: '/login' } })

    // Replace current entry (no back button)
    navigate('/dashboard', { replace: true })

    // Go back/forward
    navigate(-1) // back
    navigate(1) // forward
  }

  return <button onClick={handleLogin}>Login</button>
}

useLocation()

Access the current location:

import { useLocation } from 'slim-react-router'

function CurrentPath() {
  const location = useLocation()

  return (
    <div>
      <p>Current path: {location.pathname}</p>
      <p>Query string: {location.search}</p>
      <p>Hash: {location.hash}</p>
      <p>State: {JSON.stringify(location.state)}</p>
    </div>
  )
}

useParams()

Extract URL parameters from dynamic routes:

import { useParams } from 'slim-react-router'

function PostDetail() {
  const { userId, postId } = useParams<{ userId: string; postId: string }>()

  return <div>Post {postId} by user {userId}</div>
}

useSearchParams()

Read and update query string parameters:

import { useSearchParams } from 'slim-react-router'

function SearchResults() {
  const [searchParams, setSearchParams] = useSearchParams()

  const query = searchParams.get('q')
  const page = searchParams.get('page') || '1'

  const updateSearch = (newQuery) => {
    setSearchParams({ q: newQuery, page: '1' })
  }

  const nextPage = () => {
    setSearchParams({ q: query, page: String(Number(page) + 1) })
  }

  return (
    <div>
      <p>Searching for: {query}</p>
      <p>Page: {page}</p>
      <button onClick={nextPage}>Next Page</button>
    </div>
  )
}

useHistory()

Access the history object for advanced navigation:

import { useHistory } from 'slim-react-router'

function NavigationControls() {
  const history = useHistory()

  return (
    <div>
      <button onClick={() => history.push('/home')}>Go Home</button>
      <button onClick={() => history.replace('/home')}>
        Replace with Home
      </button>
      <button onClick={() => history.goBack()}>Back</button>
      <button onClick={() => history.goForward()}>Forward</button>
      <button onClick={() => history.go(-2)}>Go back 2 pages</button>
    </div>
  )
}

useRouteMatch()

Check if a path matches the current route:

import { useRouteMatch } from 'slim-react-router'

function Sidebar() {
  const userMatch = useRouteMatch('/users/:id')
  const settingsMatch = useRouteMatch('/settings', true) // exact match

  return (
    <div>
      {userMatch && <div>Viewing user: {userMatch.params.id}</div>}

      {settingsMatch && <SettingsPanel />}

      {/* Check multiple paths */}
      {useRouteMatch(['/dashboard', '/home']) && <QuickActions />}
    </div>
  )
}

Components

<Navigate>

Declaratively navigate to a different route. Useful for redirects:

import { Navigate, Routes, Route } from 'slim-react-router'

function App() {
  return (
    <Routes>
      {/* Redirect root to /home */}
      <Route path="/" exact element={<Navigate to="/home" />} />
      <Route path="/home" element={<HomePage />} />

      {/* Conditional redirects */}
      <Route
        path="/dashboard"
        element={isAuthenticated ? <Dashboard /> : <Navigate to="/login" />}
      />

      {/* Replace current history entry */}
      <Route path="/old-path" element={<Navigate to="/new-path" replace />} />

      {/* Navigate with state */}
      <Route
        path="/logout"
        element={<Navigate to="/login" state={{ from: '/logout' }} />}
      />
    </Routes>
  )
}