This package, `storybook-vue3-router`, provides a Storybook decorator specifically designed for Vue 3 components that utilize `vue-router`. It enables developers to wrap their routing-aware components within Storybook stories, allowing for proper testing and display of elements like `<router-view>` and `<router-link>`. The current stable version is 7.0.0, which supports Storybook v10. This library generally releases new major versions to align with new major versions of Storybook, ensuring compatibility. A key differentiator is its ability to easily provision a `vue-router` instance for stories, with options for custom routes, navigation guards, and even a mocked router for simpler use cases, streamlining the process of testing complex routing logic in isolation.
npm install storybook-vue3-routerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to apply the `vueRouter` decorator to a Storybook story for a Vue 3 component. It sets up a basic `vue-router` instance with custom routes, allowing interactive routing within Storybook stories. An initial route is also configured.
Ensure your project is running Storybook v10 (e.g., `@storybook/vue3@10.x`) before upgrading to `storybook-vue3-router@7.x`.
For Storybook v8, use `storybook-vue3-router@5.1.x`. For Storybook v7, use `storybook-vue3-router@3.x`.
For Storybook v7, use `storybook-vue3-router@3.x`. For Storybook v6, stick to `storybook-vue3-router@2.x`.
Migrate your stories to Component Story Format (CSF) if you are currently using the `storiesOf` API to ensure compatibility and leverage the full features of this decorator.
Run `npm install --save-dev storybook-vue3-router` or `yarn add --dev storybook-vue3-router`. Double-check the import statement `import { vueRouter } from 'storybook-vue3-router'`.Ensure you are using `import { vueRouter } from 'storybook-vue3-router'` for named import. Avoid `import vueRouter from 'storybook-vue3-router'` or `const vueRouter = require('storybook-vue3-router')`.Verify that `Default.decorators = [vueRouter()]` (or with custom options) is correctly set on your story. Ensure your component is wrapped by the decorator in the Storybook rendering process.