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

keepalive-for-react-router

v6.0.0

Published

React Router integration for keepalive-for-react

Readme

KeepAlive for React Router

Installation

npm install keepalive-for-react keepalive-for-react-router

v6+

npm install react-router-dom keepalive-for-react [email protected]

v7+

npm install react-router keepalive-for-react [email protected]

Usage

// v6+ [email protected]
// v7+ [email protected]
import KeepAliveRouteOutlet from "keepalive-for-react-router";

function Layout() {
    return (
        <div className="layout">
            <KeepAliveRouteOutlet />
        </div>
    );
}

Props

KeepAliveRouteOutlet inherits the core KeepAlive props, with an optional activeCacheKey and an additional wrapperComponent:

import type { ComponentType, ReactNode } from "react";
import type { KeepAliveProps } from "keepalive-for-react";

interface KeepAliveRouteOutletProps extends Omit<KeepAliveProps, "activeCacheKey"> {
    wrapperComponent?: ComponentType<{ children: ReactNode }>;
    activeCacheKey?: string;
}

| Prop | Default | Description | | ------------------ | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | activeCacheKey | location.pathname + location.search | Overrides the route's cache key. An empty string falls back to the default. The default distinguishes query strings but ignores the URL hash. | | wrapperComponent | Fragment | Wraps the outlet inside each cache node. Receives the outlet as children. | | Other core props | Core defaults | Forwarded to KeepAlive, including max, include, exclude, aliveRef, transition, viewTransition, duration, maxAliveTime, enableActivity, and customClassNames. |

Although children is present in the inherited type, rendered content always comes from useOutlet(). Use wrapperComponent to wrap that content. include and exclude match the resulting cache key.

Custom cache key and state classes

Use the pathname alone to share a cache entry across query-string changes on the same path:

import type { ReactNode } from "react";
import { useLocation } from "react-router";
import { useKeepAliveRef } from "keepalive-for-react";
import KeepAliveRouteOutlet from "keepalive-for-react-router";

function RouteWrapper({ children }: { children: ReactNode }) {
    return <main className="route-content">{children}</main>;
}

function Layout() {
    const location = useLocation();
    const aliveRef = useKeepAliveRef();

    return (
        <KeepAliveRouteOutlet
            activeCacheKey={location.pathname}
            wrapperComponent={RouteWrapper}
            aliveRef={aliveRef}
            max={18}
            transition
            customClassNames={{ active: "route-active", inactive: "route-inactive" }}
        />
    );
}

Define transition styles using .route-active and .route-inactive. Omitted customClassNames fields retain the core defaults (active and inactive); each value must be a single non-empty CSS class name.

Inside cached route components, useKeepAliveContext() exposes active, cacheKey, and the cache management methods. cacheKey identifies that component's cache node, including while it is inactive. Calls to refresh(), destroy(), or destroyOther() without a key target that node (or preserve it for destroyOther()); calls through aliveRef.current default to the currently active node.