How would you handle navigation from inside a story? #52
-
I have a story for component that renders a list of items and each item is a Say, the base route is Here is my setup:
It fails with In short, I wish to load a different story upon clicking a link in the original story. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi,
To be specific, you want to navigate through the storybook or just render a different component at the same place ? The former is not possible, the latter is just conventional routing : export const RouteWithChildren = {
render: () => (
<main>
<h1>List of items</h1>
<ul>
<li>
<NavLink to={'42'}>Book 42</NavLink>
</li>
</ul>
<Outlet />
</main>
),
parameters: {
reactRouter: reactRouterParameters({
location: {
path: '/book',
},
routing: {
path: '/book',
useStoryElement: true,
children: [
{
path: ':bookId',
Component: () => {
const routeParams = useParams();
return (
<section>
<h2>Book #{routeParams.bookId}</h2>
<p>Book details</p>
</section>
);
},
},
],
},
}),
},
}; Note you can also use the routing helper |
Beta Was this translation helpful? Give feedback.
Hi,
To be specific, you want to navigate through the storybook or just render a different component at the same place ?
The former is not possible, the latter is just conventional routing :