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

intentx-react-router

v1.0.4

Published

Intent-based routing for React. Navigate by intent instead of URLs.

Readme

🕹️ intentx-react-router

NPM Downloads

LIVE EXAMPLE

Intent‑based navigation layer for React applications.

Built on top of React Router and designed to work nicely with event‑driven architectures like eventbus-z.

Navigate by intent, not by URL.


Why intentx-react-router?

Traditional routing:

navigate("/users/42/edit")

Intent Router:

navigateIntent("edit-user", 42)

Benefits:

  • 🧠 Intent‑driven navigation
  • 🔗 URL structure fully decoupled from UI
  • 🔧 Easy URL refactor
  • 🧩 Micro‑frontend friendly
  • 📡 Event‑driven navigation support
  • 🪶 Lightweight core (~200 lines)

Installation

npm install intentx-react-router react-router@^7 react-router-dom@^7

Recommended Versions

  • react: >=18
  • react-dom: >=18
  • react-router: >=7
  • react-router-dom: >=7

Basic Setup

1. Define intents

import { createIntentRouter, NavigateFn } from "intentx-react-router"

createIntentRouter({
  "view-user": "/users/:userId/name/:page",
  "edit-user": "/users/:userId/edit",
  "checkout": "/checkout"
})

// Bind navigate in App
export function bindRouterNavigate(navigate: NavigateFn) {
  bindNavigate(navigate);
}

2. Bind React Router navigate

import React from "react"
import { useNavigate } from "react-router-dom"
import { bindNavigate } from "intentx-react-router"

export function RouterBinder() {
  const navigate = useNavigate();

  React.useEffect(() => {
    // require
    bindRouterNavigate(navigate);
  }, [navigate]);

  return null;
}

3. Use in App

import React from "react"
import { BrowserRouter, Routes } from "react-router-dom"
import { IntentLink, IntentRoute } from "intentx-react-router"
import { RouterBinder } from "./router"

import { UserPage } from "./pages/UserPage"
import { EditUserPage } from "./pages/EditUserPage"
import { CheckoutPage } from "./pages/CheckoutPage"

export default function App() {
  return (
    <BrowserRouter>
      <RouterBinder />

      <nav style={{ marginBottom: 20 }}>
        <IntentLink intent="view-user" params={[1, 2]}>View User</IntentLink>{" "}
        | <IntentLink intent="edit-user" params={1}>Edit User</IntentLink>{" "}
        | <IntentLink intent="checkout">Checkout</IntentLink>
      </nav>

      <Routes>
        <IntentRoute intent="view-user" component={UserPage} />
        <IntentRoute intent="edit-user" component={EditUserPage} />
        <IntentRoute intent="checkout" component={CheckoutPage} />
      </Routes>
    </BrowserRouter>
  )
}

Navigation

Object params

navigateIntent("view-user", {
  userId: 1,
  page: 2
})

Result:

/users/1/name/2

Array params

navigateIntent("view-user", [1,2])

Params automatically map to:

:userId
:page

Single param shortcut

navigateIntent("edit-user", 1)

Result:

/users/1/edit

Query params

Intent navigation also supports query parameters.

navigateIntent("view-user", {
  userId: 1,
  page: 2
}, {
  tab: "activity",
  filter: "recent"
})
/users/1/name/2?tab=activity&filter=recent

Query arrays are also supported:

navigateIntent("view-user", [1,2], {
  tags: ["admin", "vip"]
})

Result:

/users/1/name/2?tags=admin&tags=vip

Advanced Navigation

options, fallback, microFE

import React from "react"
import { useNavigateIntent, setFallbackPath, setSharedBus } from "intentx-react-router"
import { createEventBus } from "eventbus-z"

// Micro-frontend shared bus
const externalBus = createEventBus()
setSharedBus(externalBus)

setFallbackPath("/not-found")

function Dashboard() {
  const navigateIntent = useNavigateIntent()

  const handleCheckout = () => {
    navigateIntent("checkout", undefined, { ref: "dashboard" }, { replace: true, scrollTop: true })
  }

  return (
    <div>
      <h1>Dashboard</h1>
      <button onClick={handleCheckout}>Go to Checkout</button>
      <button
        onClick={() => {
          navigateIntent("unknown-intent")
        }}
      >
        Unknown Intent
      </button>
    </div>
  )
}

React Helpers

useNavigateIntent

import { useNavigateIntent } from "intentx-react-router"

function Button() {
  const navigateIntent = useNavigateIntent()

  return (
    <button onClick={() => navigateIntent("checkout")}>
      Checkout
    </button>
  )
}

IntentLink

import { IntentLink } from "intentx-react-router"

<IntentLink intent="view-user" params={[1,2]} query={{ tab: "profile" }}>
  Open User
</IntentLink>

Equivalent to:

<Link to="/users/1/name/2?tab=profile" />

useIntentRouter

Reads intent + params from URL.

import { useIntentRouter } from "intentx-react-router"

function Page() {
  const { intent, params } = useIntentRouter()

  console.log(intent)
  console.log(params)

  return null
}

Example result:

{
  intent: "view-user",
  params: {
    userId: "1",
    page: "2"
  }
}

IntentRoute

Intent‑aware route wrapper.

import { IntentRoute } from "intentx-react-router"

<IntentRoute
  intent="view-user"
  component={UserPage}
/>

Guards

Global guard:

addIntentGuard((intent, params) => {

  if (!isLoggedIn && intent === "checkout") {
    return "/login"
  }

})

Per‑intent guard:

addIntentGuardFor("checkout", () => {

  if (!cartReady) {
    return "/cart"
  }

})

Preload

Preload logic before navigation.

addIntentPreload("checkout", () => {
  fetchCart()
})

Manual preload:

preloadIntent("checkout")

Reverse Routing

Generate path manually.

generatePathFromIntent("view-user", [1,2], {
  tab: "activity"
})

Result:

/users/1/name/2?tab=activity

Resolve Intent From URL

resolveIntentFromUrl("/users/1/name/2?tab=activity")

Result:

{
  intent: "view-user",
  params: {
    userId: "1",
    page: "2"
  },
  query: {
    tab: "activity"
  }
}

Event-Driven Navigation

Example

import { createEventBus } from "eventbus-z"
import { navigateIntent } from "intentx-react-router"

const bus = createEventBus()

// Somewhere in your app
bus.$on("CHECKOUT_REQUESTED", (userId) => {
  navigateIntent("checkout", { userId })
})

Trigger navigation from anywhere:

bus.$emit("CHECKOUT_REQUESTED", 42)

Result:

/checkout?userId=42

Why this is powerful

  • Navigation becomes decoupled from UI components.

Instead of:

<button onClick={() => navigate("/checkout")} />

You can emit a domain event:

bus.$emit("CHECKOUT_REQUESTED")

This allows:

  • UI-agnostic navigation
  • better architecture in large apps
  • seamless micro-frontend communication

Comparison

| Criteria | intent-router | React Router | |-------------------------|---------------|--------------| | Intent-based navigation | ✅ | ❌ | | URL refactor safety | ✅ | ⚠️ | | Event-driven navigation | ✅ | ❌ | | Micro-frontend friendly | ✅ | ⚠️ | | Reverse routing | ✅ | ❌ | | Type-safe intent params | ✅ | ⚠️ | | Query support | ✅ | ⚠️ |


Architecture

Component
    ↓
navigateIntent()
    ↓
eventbus-z
    ↓
Intent Router
    ↓
React Router navigate()
    ↓
URL

License

MIT