docs/_snippets/nextjs-navigation-override-in-preview.md
// Replace your-framework with nextjs or nextjs-vite
import { getRouter } from '@storybook/your-framework/navigation';
export default {
parameters: {
nextjs: {
// ๐ Override the default navigation properties
navigation: {
pathname: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default navigation 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/navigation.mock";
const preview: Preview = {
parameters: {
nextjs: {
// ๐ Override the default navigation properties
navigation: {
pathname: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default navigation 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/navigation.mock';
const preview = definePreview({
parameters: {
nextjs: {
// ๐ Override the default navigation properties
navigation: {
pathname: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default navigation 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/navigation.mock';
const preview = definePreview({
parameters: {
nextjs: {
// ๐ Override the default navigation properties
navigation: {
pathname: '/app/',
},
},
},
async beforeEach() {
// ๐ Manipulate the default navigation method mocks
getRouter().push.mockImplementation(() => {
/* ... */
});
},
});
export default preview;