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

@edgefirst-dev/crud-routes

v1.0.0

Published

A helper to define CRUD routes in a React Router application using `routes.ts`.

Readme

React Router CRUD Helper

A helper to define CRUD routes in a React Router application using routes.ts.

Inspired by Rails resource routing.

Installation

bun add @edgefirst-dev/crud-routes

Usage

Import the crud helper in your app/routes.ts file.

import { crud } from "@edgefirst-dev/crud-routes";

Then you can use to to define routes in the exported array.

export default [...crud("users")] satisfies RouteConfig;

This will generate the following routes:

| Path | File | ID | Used to | | ---------------------- | --------------------------- | ------------- | ----------------------------- | | - | ./views/users/_layout.tsx | users.layout | Layout of every users route | | /users | ./views/users/index.tsx | users.index | Display a list of all users | | /users/new | ./views/users/new.tsx | users.new | Form to create a new user | | /users/:userId | ./views/users/show.tsx | users.show | Display the details of a user | | /users/:userId/edit | ./views/users/edit.tsx | users.edit | Form to edit a user | | /users/:userId/destroy | ./views/users/destroy.tsx | users.destroy | Action to delete a user |

Custom ID Prefix

You can also define a custom ID prefix for the generated routes.

export default [...crud("users", { idPrefix: "admin" })] satisfies RouteConfig;

This will generate the following routes:

| Path | File | ID | Used to | | ---------------------- | --------------------------- | ------------- | ----------------------------- | | - | ./views/users/_layout.tsx | admin.layout | Layout of every users route | | /users | ./views/users/index.tsx | admin.index | Display a list of all users | | /users/new | ./views/users/new.tsx | admin.new | Form to create a new user | | /users/:userId | ./views/users/show.tsx | admin.show | Display the details of a user | | /users/:userId/edit | ./views/users/edit.tsx | admin.edit | Form to edit a user | | /users/:userId/destroy | ./views/users/destroy.tsx | admin.destroy | Action to delete a user |

Nested Routes

You can also define nested routes using the React Router built-in helpers.

import { crud } from "@edgefirst-dev/crud-routes";
import { route } from "@react-router/dev/routes";

export default [
  ...crud("users", () => [
    // /users/profile
    route("profile", "./views/users/profile.tsx", { id: "users.profile" }),
  ]),
] satisfies RouteConfig;

This will generate the following routes:

| Path | File | ID | Used to | | ---------------------- | --------------------------- | ------------- | ----------------------------- | | - | ./views/users/_layout.tsx | users.layout | Layout of every users route | | /users | ./views/users/index.tsx | users.index | Display a list of all users | | /users/new | ./views/users/new.tsx | users.new | Form to create a new user | | /users/:userId | ./views/users/show.tsx | users.show | Display the details of a user | | /users/:userId/edit | ./views/users/edit.tsx | users.edit | Form to edit a user | | /users/:userId/destroy | ./views/users/destroy.tsx | users.destroy | Action to delete a user | | /users/profile | ./views/users/profile.tsx | users.profile | Display the profile of a user |

The nested route will be added to the layout of the CRUD.

Member Routes

A member route is a route attached to a specific resource. For example, in the resource users a member can be nested inside /users/:userId.

import { crud, route } from "@edgefirst-dev/crud-routes";

export default [
  ...crud("users", () => [
    route("profile", "./views/users/profile.tsx", {
      id: "users.profile",
      on: "member",
    }),
  ]),
] satisfies RouteConfig;

Here we're using the route helper exported by this package to define a new route. The on option is used to define the type of route. In this case, it's a member route.

A member route could also be another CRUD

import { crud } from "@edgefirst-dev/crud-routes";

export default [
  ...crud("users", () => [
    ...crud("posts", { on: "member" }), // /users/:userId/posts and other CRUD routes
  ]),
] satisfies RouteConfig;

Collection Routes

A collection route is a route attached to a specific resource. For example, in the resource users a collection can be nested inside /users.

import { crud, route } from "@edgefirst-dev/crud-routes";

export default [
  ...crud("users", () => [
    route("profile", "./views/users/profile.tsx", {
      id: "users.profile",
      on: "member",
    }),
  ]),
] satisfies RouteConfig;

Here we're using the route helper exported by this package to define a new route. The on option is used to define the type of route. In this case, it's a collection route.

A collection route could also be another CRUD

import { crud } from "@edgefirst-dev/crud-routes";

export default [
  ...crud("users", () => [
    ...crud("posts", { on: "collection" }), // /users/posts and other CRUD routes
  ]),
] satisfies RouteConfig;

Shallow Routes

Shallow routes allows you to nest a resource inside another resource, but limiting it to only the index and new routes. While the show, edit, and destroy routes are not nested, and with the same layout for both nested and non-nested routes.

import { crud } from "@edgefirst-dev/crud-routes";

export default [
  ...crud("users", () => [...crud("posts", { on: "shallow" })]),
] satisfies RouteConfig;

This will generate the following routes:

| Path | File | ID | Used to | | ------------------------ | --------------------------- | --------------- | ----------------------------- | | - | ./views/users/_layout.tsx | users.layout | Layout of every users route | | /users | ./views/users/index.tsx | users.index | Display a list of all users | | /users/new | ./views/users/new.tsx | users.new | Form to create a new user | | /users/:userId | ./views/users/show.tsx | users.show | Display the details of a user | | /users/:userId/edit | ./views/users/edit.tsx | users.edit | Form to edit a user | | /users/:userId/destroy | ./views/users/destroy.tsx | users.destroy | Action to delete a user | | /users/:userId/posts | ./views/posts/index.tsx | users.posts | Display a list of all posts | | /users/:userId/posts/new | ./views/posts/new.tsx | users.posts.new | Form to create a new post | | /posts/:postId | ./views/posts/show.tsx | posts.show | Display the details of a post | | /posts/:postId/edit | ./views/posts/edit.tsx | posts.edit | Form to edit a post | | /posts/:postId/destroy | ./views/posts/destroy.tsx | posts.destroy | Action to delete a post |

Note that shallow routes will not include a layout for the nested resource. This is because the layout is shared with the parent resource.

Author