Storybook: "invariant expected app router to be mounted" in stories with useRouter
#50068
Answered
by
giovannivocale-molar
gvocale
asked this question in
App Router
-
In Storybook, when displaying a component using I understand Storybook 7 should be able to mock Next router out of the box. I have no issue displaying stories importing the old Pages runtime.js:4 Error: invariant expected app router to be mounted
at useRouter (navigation.js:136:1)
at NavBack (index.tsx:5:1)
at renderWithHooks (react-dom.development.js:16305:1)
at mountIndeterminateComponent (react-dom.development.js:20074:1)
at beginWork (react-dom.development.js:21587:1)
at beginWork$1 (react-dom.development.js:27426:1)
at performUnitOfWork (react-dom.development.js:26557:1)
at workLoopSync (react-dom.development.js:26466:1)
at renderRootSync (react-dom.development.js:26434:1)
at recoverFromConcurrentError (react-dom.development.js:25850:1) |
Beta Was this translation helpful? Give feedback.
Answered by
giovannivocale-molar
May 22, 2023
Replies: 1 comment 4 replies
-
Found the solution here https://storybook.js.org/blog/integrate-nextjs-and-storybook-automatically/ under Needed to add the following parameter to the stories of components using export const Example = {
parameters: {
nextjs: {
appDirectory: true,
},
},
}; |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
gvocale
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found the solution here https://storybook.js.org/blog/integrate-nextjs-and-storybook-automatically/ under
next/navigation
Needed to add the following parameter to the stories of components using
next/navigation