Gathering detailed insights and metrics for storybook-react-router
Gathering detailed insights and metrics for storybook-react-router
Gathering detailed insights and metrics for storybook-react-router
Gathering detailed insights and metrics for storybook-react-router
storybook-addon-react-router-v6
Use React Router v6 in your stories
storybook-addon-remix-react-router
Use Remix React Router in your stories. (Formerly storybook-addon-react-router-v6)
@types/storybook-react-router
TypeScript definitions for storybook-react-router
storybook-react-router-dom
A storybook decorator that allows you to use routing-aware components in your stories.
A storybook decorator that allows you to use routing-aware components in your stories
npm install storybook-react-router
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
258 Stars
58 Commits
32 Forks
3 Watchers
15 Branches
6 Contributors
Updated on Oct 16, 2024
Latest Version
1.0.8
Package Id
storybook-react-router@1.0.8
Size
4.77 kB
NPM Version
lerna/3.16.4/node@v10.15.3+x64 (darwin)
Node Version
10.15.3
Published on
Sep 30, 2019
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
4
A Storybook decorator that allows you to use your routing-aware components.
npm install --save-dev storybook-react-router
The decorator is actually a function which wraps the Router
instance. It accepts two optional arguments that you can use if you want to build a prototype of your navigation within storybook or if you need more control over the router itself.
In its default behavior the decorator just log every route action perfomed using the storybook action logger. If you are fine with the default arguments you can add globally the StoryRouter
decorator, however if you need to specify some of the arguments you have to use the decorator for every story that needs it.
Suppose you have a component that uses react-router Route
and Link
:
1import React from 'react'; 2import { Route, Link } from 'react-router-dom'; 3 4const ChildId = ({match}) => ( 5 <div> 6 <h3>ID: {match.params.id}</h3> 7 </div> 8); 9 10const ComponentParams = () => ( 11 <div> 12 <ul> 13 <li><Link to="/accounts/netflix">Netflix</Link></li> 14 <li><Link to="/accounts/sky">Sky</Link></li> 15 </ul> 16 <Route path="/accounts/:id" component={ChildId}/> 17 </div> 18); 19 20export default ComponentParams;
you can add the StoryRouter
decorator to your story this way:
1import { storiesOf } from '@storybook/react'; 2import StoryRouter from 'storybook-react-router'; 3 4import ComponentParams from '<your_component_path>/ComponentParams'; 5 6storiesOf('Params', module) 7 .addDecorator(StoryRouter()) 8 .add('params', () => ( 9 <ComponentParams/> 10 ));
If you want to use StoryRouter
in all your stories, you can also add it globally by editing your Storybook config.js
file:
1import { configure, addDecorator } from '@storybook/react'; 2import StoryRouter from 'storybook-react-router'; 3 4addDecorator(StoryRouter()); 5 6// ...your config 7
The important thing is to call addDecorator
before calling configure
, otherwise it will not work!
The first argument is an object that you can use to extend the default behavior.
Every time that a key in the object matches with a path Storybook will call the callback specified for the corresponding value with the destination path as argument.
This way you can for example link stories together using the links
addons with the linkTo function.
The match is performed using the path-to-regexp module so you can also use parameter names and regexp within the link keys.
The second argument is another object which will be forwarded to the wrapped MemoryRouter
as props. This allows you to write stories having a specific url location or using advanced functionalities as asking the user confirmation before exiting from a location.
You can find more examples in the provided stories. You can run them cloning this repository and executing (supposing you have installed globally lerna):
yarn install && yarn bootstrap
yarn storybook-react-examples
As the wrapped Router creates a new history object for each story you cannot pass the history from a story to another one and so you cannot implement a back or forward button which works among stories.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
162 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More