我用的是next13,所以我把故事书升级到了版本7。
然而,当我启动故事书时,我得到了next-route错误。
原因是我正在AppContext中使用Router,如果我注解掉Router部分,故事书就能工作。
我正在根据AppContext中的错误内容转换到屏幕。(使用路由器)。
误差
NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
import * as React from 'react';
import { initialize, mswDecorator } from 'msw-storybook-addon';
import { AppContextProvider } from '../src/context/AppContextProvider';
import { NextPageWithLayout } from '../src/pages/_app.page';
import {
mockOrganization,
mockList,
} from '../src/stories/mocks/msw-handlers';
import 'style/index.css';
import 'style/utils/slider.css';
import 'tailwindcss/tailwind.css';
initialize();
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
layout: 'fullscreen',
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
msw: {
handlers: {
'/organization': mockOrganization(),
'/master': mockList(),
},
},
chromatic: {
viewports: [375, 768, 1200],
},
};
export const decorators = [
(Story: NextPageWithLayout) => {
const getLayout = Story.getLayout ?? (page => page);
return <AppContextProvider>{getLayout(<Story />)}</AppContextProvider>;
},
mswDecorator,
];
1条答案
按热度按时间xxhby3vn1#
确保路由器已正确初始化并安装在Storybook设置中