Ability to pass URL parameters to stories
See original GitHub issueIs your feature request related to a problem? Please describe.
We’re using URL parameters in many of our components, e.g ?mock=true. However, storybook (v5.0.2) discards all the additional URL parameters I am giving to it.
Describe the solution you’d like
The best solution would be if the user-defined URL parameters of the storybook would be automatically added to the iframe of the story. For example, it could be something like ?user-mock=true. Which would be added to the iframe of the story as ?mock=true.
If that’s not possible, it would be nice if storybook at least wouldn’t delete the unknown url parameters, as it does now. Then I could perhaps access from the story via parent.window.location or something like that.
Describe alternatives you’ve considered Without URL option, I would have to use cookies or something along these lines 😦
Are you able to assist bring the feature to reality? Maybe…
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:24 (12 by maintainers)
Top Related StackOverflow Question
Did we use to pass the URL from the manager to the preview unmodified?
@vitalybe I am curious about the use case here. I assume your components read from the URL directly? How do you go about setting the URL? Do you have to manually change it when you look at certain stories?
Perhaps we could have an addon that sets the preview URL query parameters based on a story parameter? Maybe that is a nicer solution?
@vitalybe an option for an alternative would be addon-context, and reading the mock boolean from there. You’d be able to switch mocking on and off from the storybook UI.
I understand if that’s not really feasible. I second @tmeasday’s suggestion of an queryParameters addon that would read parameters.query and change the url accordingly before calling the storyFn.