Created
September 28, 2021 20:08
-
-
Save javierguzman/a5af04829f5ca00cae74041d22e5a39b to your computer and use it in GitHub Desktop.
Storybook with react-router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const withMemoryRouter = (StoryComponent, { parameters: currentURL }) => { | |
if (!currentURL) { | |
return <StoryComponent />; | |
} | |
const { path, route } = currentURL; | |
console.log('Current url available'); | |
console.log(path, route); | |
return ( | |
<MemoryRouter initialEntries={[encodeURI(route)]}> | |
<Route path={path}> | |
<StoryComponent /> | |
</Route> | |
</MemoryRouter> | |
); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment