Gathering detailed insights and metrics for storybook-addon-react-router-v6
Gathering detailed insights and metrics for storybook-addon-react-router-v6
Gathering detailed insights and metrics for storybook-addon-react-router-v6
Gathering detailed insights and metrics for storybook-addon-react-router-v6
storybook-addon-remix-react-router
Use Remix React Router in your stories. (Formerly storybook-addon-react-router-v6)
@storybook/nextjs
Storybook for Next.js
react-router-dom
Declarative routing for React web applications
storybook-addon-turbo-build
Storybook Addon to improve build performance
Use your app router in your stories. A decorator made for Remix React Router and Storybook
npm install storybook-addon-react-router-v6
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
50 Stars
224 Commits
13 Forks
4 Watching
4 Branches
3 Contributors
Updated on 27 Nov 2024
TypeScript (98.92%)
JavaScript (0.99%)
Shell (0.05%)
HTML (0.03%)
Cumulative downloads
Total Downloads
Last day
-2.6%
13,013
Compared to previous day
Last week
1.5%
68,175
Compared to previous week
Last month
2.8%
295,758
Compared to previous month
Last year
59.4%
4,915,328
Compared to previous year
2
10
48
Use Remix React Router in your stories.
✨Notice ✨
The package has been renamed storybook-addon-remix-react-router
.
The repository has also been renamed, so you are on the right page.
The migration is mandatory to support Storybook 8.
✅ Support for Storybook 8 with storybook-addon-remix-react-router@3
.
✅ You can now use useStoryElement
to inject the story at multiple points.
✅ The routing
parameter now accept a string, that will be used both as the route path and the location pathname.
Install the package
npm i -D storybook-addon-remix-react-router
Add it to your storybook configuration:
1// .storybook/main.ts 2 3export default { 4 addons: ['storybook-addon-remix-react-router'], 5} satisfies StorybookConfig;
To add the router to all the stories of a component, simply add it to the decorators
array.
Note that parameters.reactRouter
is optional, by default the router will render the component at /
.
1import { withRouter, reactRouterParameters } from 'storybook-addon-remix-react-router'; 2 3export default { 4 title: 'User Profile', 5 render: () => <UserProfile />, 6 decorators: [withRouter], 7 parameters: { 8 reactRouter: reactRouterParameters({ 9 location: { 10 pathParams: { userId: '42' }, 11 }, 12 routing: { path: '/users/:userId' }, 13 }), 14 }, 15};
To change the config for a single story, you can do the following :
1import { withRouter, reactRouterParameters } from 'storybook-addon-remix-react-router'; 2 3export default { 4 title: 'User Profile', 5 render: () => <UserProfile />, 6 decorators: [withRouter], 7}; 8 9export const FromHomePage = { 10 parameters: { 11 reactRouter: reactRouterParameters({ 12 location: { 13 pathParams: { userId: '42' }, 14 searchParams: { tab: 'activityLog' }, 15 state: { fromPage: 'homePage' }, 16 }, 17 routing: { 18 path: '/users/:userId', 19 handle: 'Profile', 20 }, 21 }), 22 }, 23};
To wrap all your project's stories inside a router by adding the decorator in your preview.js
file.
1// .storybook/preview.js 2 3export default { 4 decorators: [withRouter], 5 parameters: { 6 reactRouter: reactRouterParameters({ ... }), 7 } 8} satisfies Preview;
To specify anything related to the browser location, use the location
property.
1type LocationParameters = { 2 path?: string | ((inferredPath: string, pathParams: Record<string, string>) => string | undefined); 3 pathParams?: PathParams; 4 searchParams?: ConstructorParameters<typeof URLSearchParams>[0]; 5 hash?: string; 6 state?: unknown; 7};
If location.path
is not provided, the browser pathname will be generated using the joined path
s from the routing
property and the pathParams
.
You can provide a function to path
.
It will receive the joined path
s from the routing property and the pathParams
as parameters.
If the function returns a string
, is will be used as is. It's up to you to call generatePath
from react-router
if you need to.
If the function returns undefined
, it will fallback to the default behavior, just like if you didn't provide any value for location.path
.
You can set routing
to anything accepted by createBrowserRouter
.
To make your life easier, storybook-addon-remix-react-router
comes with some routing helpers :
1export const MyStory = { 2 parameters: { 3 reactRouter: reactRouterParameters({ 4 routing: reactRouterOutlet(<MyOutlet />), 5 }), 6 }, 7};
The following helpers are available out of the box :
1reactRouterOutlet(); // Render a single outlet 2reactRouterOutlets(); // Render multiple outlets 3reactRouterNestedOutlets(); // Render multiple outlets nested one into another 4reactRouterNestedAncestors(); // Render the story as an outlet of nested outlets
You can also create your own helper and use the exported type RoutingHelper
to assist you :
1import { RoutingHelper } from 'storybook-addon-remix-react-router'; 2 3const myCustomHelper: RoutingHelper = () => { 4 // Routing creation logic 5};
RouterRoute
is basically the native RouteObject
from react-router
; augmented with { useStoryElement?: boolean }
.
If you want to accept a JSX and turn it into a RouterRoute
, you can use the exported function castRouterRoute
.
Just set { useStoryElement: true }
in the routing config object.
Navigation events, loader and actions are logged, for you to better understand the lifecycle of your components.
Version 6.4+
of react-router
is required.
This package aims to support Storybook > 7
and React > 16
.
✅ Storybook 8.0
✅ Storybook 7.0
✅ React 18
✅ React 17
✅ React 16
If you have an issue with any version, open an issue.
Contributions are welcome.
Before writing any code, file an issue to showcase the bug or the use case for the feature you want to see in this addon.
This package is released under the Apache 2.0 license.
No vulnerabilities found.
No security vulnerabilities found.