Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

NextRouter was not mounted. in Next.js 13 #72

Open
p-chan opened this issue Dec 14, 2022 · 3 comments
Open

NextRouter was not mounted. in Next.js 13 #72

p-chan opened this issue Dec 14, 2022 · 3 comments

Comments

@p-chan
Copy link

p-chan commented Dec 14, 2022

In my project, I updated storybook-addon-next-router to v4.0.2 and it did not work.
Storybook say NextRouter was not mounted.
Is it just me? Is it the same for others?


Versions:

next: 13.0.5
@storybook/react: 6.5.12
storybook-addon-next-router: 4.0.2

@p-chan
Copy link
Author

p-chan commented Dec 14, 2022

I have found a tentative solution and will share it with you guys.

In .storybook/preview.js

import { WithNextRouter } from "storybook-addon-next-router/dist/decorators";

export const decorators = [
  (Story) => {
    return (
      ...
    );
  },
  // Add this line!
  WithNextRouter,
];

@kristinlindquist
Copy link

@p-chan I ran same problem and your fix worked for me. Thank you!

@ghost
Copy link

ghost commented Dec 21, 2022

Storybook 7.0.0 will have built-in next/router mock functionality, so this addon is no longer needed.
If you use Next.js 13, you may want to use Storybook 7.0.0-beta.13 or later.

https://storybook.js.org/blog/integrate-nextjs-and-storybook-automatically/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants