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

@uxf/router

v11.110.0

Published

UXF Router

Readme

@uxf/router

Installation

yarn add @uxf/router
  • Create routes directory
  • Create routes.ts and index.ts inside routes directory:
// routes/routes.ts

import { createRouter } from "@uxf/router";

export default createRouter(
    {
        index: {
            path: "/"
        },
        "admin/index": {
            path: "/admin",
            schema: object({
                param1: optional(number())
            })
        },
        "blog/detail": {
            path: "/blog/[id]",
            schema: object({
                id: number()
            })
        },
        "localized-route": {
            path: {
                en: "/en/home",
                cs: "/cs/domu"
            },
            schema: object({
                term: optional(string()),
            })
        }
    } as const, 
    { 
        locales: ["cs", "en"],
        baseUrl: "https://www.uxf.cz"
    } as const
);
// routes/index.ts

import router from "./routes";
import { UxfGetServerSideProps, UxfGetStaticProps, ExtractSchema } from "@uxf/router";
import { PreviewData as NextPreviewData } from "next/types";

export const {
    routeToUrl, 
    sitemapGenerator, 
    useQueryParams, 
    useQueryParamsStatic 
} = router;

export type GetRouteSchema<K extends keyof RouteList> = ExtractSchema<RouteList[K]>;

export type GetStaticProps<
    Route extends keyof RouteList,
    Props extends { [key: string]: any } = { [key: string]: any },
    PreviewData extends NextPreviewData = NextPreviewData,
    > = UxfGetStaticProps<RouteList, Route, Props, PreviewData>;

export type GetServerSideProps<
    Route extends keyof RouteList,
    Props extends { [key: string]: any } = { [key: string]: any },
    PreviewData extends NextPreviewData = NextPreviewData,
    > = UxfGetServerSideProps<RouteList, Route, Props, PreviewData>;

Add configuration to tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@app-routes": [
        "routes"
      ]
    }
  }
}

useQueryParams

import { useQueryParams } from "@app-routes";
import { queryParamToNumber } from "./helper";

// can be used on SSR pages
const [query, { push, replace }] = useQueryParams("route-name");

// must be used on static pages, because router is not ready on first render
// query is null if router is not ready
const [query, { push, replace }] = useQueryParamsStatic("route-name");

Next Link

// pages/index.js

import Link from "next/link";
import { routeToUrl } from "@app-routes";

export default () => (
    <Link href={routeToUrl("blog/detail", { id: 12 })}>
      Hello world
    </Link>
)

RouteMatcher

import { createRouteMatcher } from "@app-routes";

// create active resolver
const routeMatcher = createRouteMatcher("admin/index", { param1: 123 });
// or
const routeMatcher = createRouteMatcher("admin/index");

// how to use in component

function MyComponent() {
    const router = useRouter();
    const isRouteActive = routeMatcher(router);
    
    return <div>{isRouteActive ? "active" : "not active"}</div>;
}

Custom route matchers

function createPathnameRouteMatcher(path: string): RouteMatcher {
    return (router) => {
        return router.pathname.startsWith(path);
    }
}
import { getCurrentRoute } from "@app-routes";

function createCustomRouteMatcher(): RouteMatcher {
    return (router) => {
        const { route, params } = getCurrentRoute(router);
        if (route === "admin/index") {
            // do something
        } else if (route === "admin/form") {
            // do something
        }
    }
}

Merge multiple route matchers

import { mergeRouteMatchers } from "@uxf/router";

const routeMatcher = mergeRouteMatchers([
    createRouteMatcher("admin/index"), 
    createRouteMatcher("admin/form"),
]);

Type-safe route params

import { GetRouteSchema } from "@app-routes";

const blogProps: GetRouteSchema<"blog/detail"> = {
    id: 1,
}

GetStaticProps

import { GetStaticProps } from "@app-routes";
import { queryParamToNumber } from "@uxf/router";

export const getStaticProps: GetStaticProps<"blog/detail"> = (context) => {
    const id = queryParamToNumber(context.params?.id); // context.params is of type { id: number } | undefined
}

GetServerSideProps

import { GetServerSideProps } from "@app-routes";
import { queryParamToNumber } from "@uxf/router";

export const getServerSideProps: GetServerSideProps<"blog/detail"> = (context) => {
    const id = queryParamToNumber(context.params?.id); // context.params is of type { id: number } | undefined
}

Sitemap

Create sitemap items

// sitemap-items.ts in @app-routes

import { createSitemapGenerator, routeToUrl } from "@app-routes";

export const sitemapItems = createSitemapGenerator({baseUrl: 'http://localhost:3000', defaultPriority: 1})
    .add("index", async (route) => ({ loc: routeToUrl(route) }))
    .add("blog/detail", async (route) => [
        { loc: routeToUrl(route, {id: 1}), priority: 2 },
        { loc: routeToUrl(route, {id: 2}), priority: 2 },
    ])
    .skip("admin/index")
    .exhaustive();

sitemap.xml

// pages/sitemap.xml.tsx

import React from "react";
import { NextPage } from "next";
import { sitemapItems } from "@app-routes";

const Page: NextPage = () => null;

Page.getInitialProps = async (ctx) => {
    if (ctx.res) {
        ctx.res.setHeader("Content-Type", "text/xml");
        ctx.res.write(await sitemapItems.toXml());
        ctx.res.end();
    }

    return {};
};

export default Page;

sitemap.json

// pages/sitemap.json.tsx

import React from "react";
import { NextPage } from "next";
import { sitemapItems } from "@app-routes";

const Page: NextPage = () => null;

Page.getInitialProps = async (ctx) => {
    if (ctx.res) {
        ctx.res.setHeader("Content-Type", "text/json");
        ctx.res.write(await sitemapItems.toJson());
        ctx.res.end();
    }

    return {};
};

export default Page;