docs/_snippets/nextjs-router-override-in-preview.md
// Replace your-framework with nextjs or nextjs-vite
import { getRouter } from '@storybook/your-framework/router';
export default {
parameters: {
nextjs: {
// ๐ Override the default router properties
router: {
basePath: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default router method mocks
getRouter().push.mockImplementation(() => {
/* ... */
});
},
};
// Replace your-framework with nextjs or nextjs-vite
import type { Preview } from '@storybook/your-framework';
// ๐ Must include the `.mock` portion of filename to have mocks typed correctly
import { getRouter } from "@storybook/your-framework/router.mock";
const preview: Preview = {
parameters: {
nextjs: {
// ๐ Override the default router properties
router: {
basePath: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default router method mocks
getRouter().push.mockImplementation(() => {
/* ... */
});
},
};
export default preview;
// Replace your-framework with nextjs or nextjs-vite
import { definePreview } from '@storybook/your-framework';
// ๐ Must include the `.mock` portion of filename to have mocks typed correctly
import { getRouter } from '@storybook/your-framework/router.mock';
const preview = definePreview({
parameters: {
nextjs: {
// ๐ Override the default router properties
router: {
basePath: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default router method mocks
getRouter().push.mockImplementation(() => {
/* ... */
});
},
});
export default preview;
// Replace your-framework with nextjs or nextjs-vite
import { definePreview } from '@storybook/your-framework';
// ๐ Must include the `.mock` portion of filename to have mocks typed correctly
import { getRouter } from '@storybook/your-framework/router.mock';
const preview = definePreview({
parameters: {
nextjs: {
// ๐ Override the default router properties
router: {
basePath: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default router method mocks
getRouter().push.mockImplementation(() => {
/* ... */
});
},
});
export default preview;