Registry / web-framework / storybook-vue3-router

storybook-vue3-router

JSON →
library7.0.0jsnpmunverified

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-router
INSTALL
IMPORT
SIG · STORYBOOK-VUE3-ROU
S
storybook-vue3-router
web-frameworkjavascriptv7.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vueRouter
import { vueRouter } from 'storybook-vue3-router'
const vueRouter = require('storybook-vue3-router')
This library is primarily designed for ESM environments. Using CommonJS `require` will likely lead to module resolution errors in most modern Storybook setups.
vueRouter
import { vueRouter } from 'storybook-vue3-router'
import vueRouter from 'storybook-vue3-router'
The `vueRouter` function is a named export, not the default export. Importing it incorrectly as a default will result in `undefined`.

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.

import { h, defineComponent } from 'vue'; import { RouterLink, RouterView } from 'vue-router'; import { vueRouter } from 'storybook-vue3-router'; import type { StoryFn } from '@storybook/vue3'; // A simple component to demonstrate routing functionality const MyRouterComponent = defineComponent({ template: ` <div> <h1>Current Route: {{$route.path}}</h1> <nav> <RouterLink to="/">Home</RouterLink> | <RouterLink to="/about">About</RouterLink> | <RouterLink to="/admin">Admin</RouterLink> </nav> <hr/> <RouterView /> </div> `, components: { RouterLink, RouterView } }); // Dummy components for custom routes const HomeComponent = defineComponent({ template: '<div>Home Page Content</div>' }); const AboutComponent = defineComponent({ template: '<div>About Page Content</div>' }); const AdminComponent = defineComponent({ template: '<div>Admin Page Content (simulated)</div>' }); // Define custom routes for the Storybook decorator const customRoutes = [ { path: '/', name: 'home', component: HomeComponent }, { path: '/about', name: 'about', component: AboutComponent }, { path: '/admin', name: 'admin', component: AdminComponent } ]; const Template: StoryFn = (args) => ({ components: { MyRouterComponent }, setup() { return { args }; }, template: '<MyRouterComponent />', }); export const Default = Template.bind({}); Default.decorators = [ // Apply the vueRouter decorator with custom routes vueRouter(customRoutes, { initialRoute: '/about' }) ]; Default.parameters = { // Optional: You can also specify the initial route via parameters // vueRouter: { // route: '/about' // } };
Debug
Known issues
breakingVersion 7.x of `storybook-vue3-router` introduces breaking changes by upgrading to support Storybook v10. Previous versions are not compatible.
fix
Ensure your project is running Storybook v10 (e.g., `@storybook/vue3@10.x`) before upgrading to `storybook-vue3-router@7.x`.
affects: >=7.0.0
breakingVersion 5.x of `storybook-vue3-router` introduces breaking changes for compatibility with Storybook v8. Projects using older Storybook versions should not upgrade to `5.x`.
fix
For Storybook v8, use `storybook-vue3-router@5.1.x`. For Storybook v7, use `storybook-vue3-router@3.x`.
affects: >=5.0.0 <7.0.0
breakingVersion 3.x of `storybook-vue3-router` introduced breaking changes to support Storybook v7. Older Storybook v6 projects should continue using `2.x`.
fix
For Storybook v7, use `storybook-vue3-router@3.x`. For Storybook v6, stick to `storybook-vue3-router@2.x`.
affects: >=3.0.0 <5.0.0
gotchaThis decorator is designed to work with Storybook's Component Story Format (CSF) and hoisted CSF annotations. It has not been tested and is not recommended for use with the older `storiesOf` API.
fix
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.
affects: >=2.0.0
Errors
Common errors & fixes
Module not found: Can't resolve 'storybook-vue3-router'
The package is not installed or the import path is incorrect.
fix
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'`.
TypeError: (0 , storybook_vue3_router__WEBPACK_IMPORTED_MODULE_0__.vueRouter) is not a function
The `vueRouter` function was imported incorrectly, often as a default import instead of a named import, or via `require` in an ESM context.
fix
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')`.
Cannot read properties of undefined (reading '$route') or 'TypeError: Cannot read properties of null (reading 'path')'
Your Vue component is trying to access `$route` or `$router` but the `vueRouter` decorator has not been correctly applied or configured for the story.
fix
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.
Upgrade
Version history
7.0.0latest on npm
Audit
Dependencies
@storybook/vue3requiredCore Storybook framework adapter, required peer dependency.
vuerequiredCore Vue framework, required peer dependency.
vue-routerrequiredCore Vue routing library, required peer dependency.
Agent activity
8 hits · last 30 days
node
8
Resources
storybook-vue3-router — npm install storybook-vue3-router · libregistry