Skip to content

Add a way to declare redirects #15084

@TrevorBurnham

Description

@TrevorBurnham

Is your feature request related to a problem? Please describe

I want to move a story from A/MyComponent to B/MyComponent to better organize my storybook. However, this would mean that links to ?path=/docs/a-mycomponent would no longer take users to the MyComponent story. I want to preserve compatibility with those links.

Describe the solution you'd like

I'd like to be able to declare redirects, perhaps as entries in the Storybook config:

module.exports = {
  stories: ['../src/**/*.stories.@(js|mdx)'],
  addons: ['@storybook/addon-essentials'],
  redirects: [
    {from: 'A/MyComponent', to: 'B/MyComponent'}
  ]
}

Describe alternatives you've considered

I tried declaring a story with the same title as the old one that returns a linkTo the new one:

import {linkTo} from '@storybook/addon-links';

export default {
  title: 'A/MyComponent',
  parameters: {
    docs: {
      page: () => {
        linkTo('B/MyComponent')();
        return <div />;
      },
    },
  },
};

This works, but it results in an extra entry being added to the sidebar/search: The sidebar shows both A/MyComponent and B/MyComponent. And apart from the sidebar issue (which could be addressed by #9209), it's a lot of code for a simple redirect.

Are you able to assist to bring the feature to reality?

Yes, I'd be happy to work on this as either a feature in Storybook proper (part of @storybook/router?) or as an addon. (The storybook-redirect addon is made for a different purpose.) I could use some pointers on how the router works, though.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions