Storybook Addon for Remix React Router
This Storybook addon integrates Remix React Router into your stories, enabling comprehensive testing and demonstration of components that rely on React Router's navigation and state management. The current stable version is 6.1.0, released recently in March 2026, indicating an active development and maintenance cadence with frequent updates to support new Storybook and React Router versions. A key differentiator is its explicit support for `react-router@7` and newer, making a clear distinction from earlier versions (v3 and below) that supported `react-router-dom`. It provides a `withRouter` decorator and `reactRouterParameters` to configure routes, locations, path parameters, search parameters, and state directly within your stories, allowing for precise control over the routing context for each component variant. This addon ensures that components designed for a Remix React Router environment can be faithfully rendered and interacted with in isolation within Storybook.
Common errors
-
Module not found: Can't resolve 'react-router-dom'
cause Attempting to use `storybook-addon-remix-react-router` v4 or higher while your project or stories still rely on `react-router-dom` imports or usage patterns.fixUpgrade your project to use `react-router` directly (and remove `react-router-dom`) or downgrade the addon to version `^3.0.0` if `react-router-dom` usage is required. -
TypeError: Cannot read properties of undefined (reading 'reactRouter')
cause The `reactRouterParameters` object is either not properly set in `parameters.reactRouter` or `withRouter` decorator is missing.fixEnsure that `decorators: [withRouter]` is applied to your component's meta or story, and `parameters.reactRouter` is correctly defined using `reactRouterParameters({...})`. -
TypeError: (0 , storybook_addon_remix_react_router__WEBPACK_IMPORTED_MODULE_2__.reactRouterParameters) is not a function
cause Incorrect import of `reactRouterParameters` (e.g., attempting a default import or a typo in the named import).fixVerify the import statement is `import { reactRouterParameters } from 'storybook-addon-remix-react-router';` (named import with correct casing). -
Error: Storybook encountered an error during loading addons. It might be due to an incompatible addon version or a broken addon.
cause Mismatch between the addon's major version and your Storybook installation's major version.fixCheck the addon's README for its compatibility table and install the version that specifically supports your Storybook major version (e.g., `storybook-addon-remix-react-router@^6.0.0` for Storybook 10).
Warnings
- breaking Version 4.0.0 of `storybook-addon-remix-react-router` dropped support for `react-router-dom` imports in favor of `react-router` only, aligning with Remix's deprecation of `react-router-dom` in new projects.
- breaking Major versions of this addon are often tied to specific Storybook versions. v6 supports Storybook 10, v5 supports Storybook 9, v4 supports Storybook 8, and v3 supports Storybook 8. Using a mismatched addon version with your Storybook installation can lead to runtime errors or addon not loading.
- gotcha In version 4.0.1, a bug was fixed regarding an incorrect export path, which could lead to 'Module not found' errors, particularly when configuring the addon.
- gotcha The `location.path` property in `reactRouterParameters` can be provided as a function. If this function returns a string, it is used 'as is', and it's the developer's responsibility to call `generatePath` from `react-router` if needed.
Install
-
npm install storybook-addon-remix-react-router -
yarn add storybook-addon-remix-react-router -
pnpm add storybook-addon-remix-react-router
Imports
- withRouter
const { withRouter } = require('storybook-addon-remix-react-router');import { withRouter } from 'storybook-addon-remix-react-router'; - reactRouterParameters
import reactRouterParameters from 'storybook-addon-remix-react-router';
import { reactRouterParameters } from 'storybook-addon-remix-react-router'; - StorybookConfig
import type { StorybookConfig } from '@storybook/types';
Quickstart
import { withRouter, reactRouterParameters } from 'storybook-addon-remix-react-router';
import type { Meta, StoryObj } from '@storybook/react';
import { Outlet, Link } from 'react-router-dom'; // Example component using router hooks
const UserProfile = () => (
<div>
<h1>User Profile Page</h1>
<p>Viewing profile for user ID: <Outlet /></p>
<nav>
<Link to="/users/42">Profile</Link> | <Link to="/users/42?tab=activityLog">Activity Log</Link>
</nav>
</div>
);
const meta: Meta<typeof UserProfile> = {
title: 'User Profile',
component: UserProfile,
decorators: [withRouter],
parameters: {
reactRouter: reactRouterParameters({
location: {
pathParams: { userId: '42' },
searchParams: { tab: 'profile' },
state: { fromPage: 'homePage' }
},
routing: { path: '/users/:userId' },
}),
},
};
export default meta;
type Story = StoryObj<typeof UserProfile>;
export const Default: Story = {};
export const ActivityLogTab: Story = {
parameters: {
reactRouter: reactRouterParameters({
location: {
pathParams: { userId: '42' },
searchParams: { tab: 'activityLog' }
},
routing: { path: '/users/:userId' }
})
}
};