Back to Storybook

Tanstack React Route Tree Story

docs/_snippets/tanstack-react-route-tree-story.md

10.4.01.6 KB
Original Source
ts
import type { Meta, StoryObj } from '@storybook/tanstack-react';

// ๐Ÿ‘‡ Route file is part of the app route tree
import { Route } from './routes/_authenticated/settings/profile';

const meta = {
  parameters: {
    tanstack: {
      router: {
        // ๐Ÿ‘‡ Storybook walks up the tree to root and duplicates the full route tree,
        //    so parent layouts (e.g. the authenticated shell) also render.
        route: Route,
        path: '/settings/profile',
        // ๐Ÿ‘‡ Stub out any parent route guards so the story can render standalone.
        routeOverrides: {
          '/_authenticated': { beforeLoad: () => {} },
        },
      },
    },
  },
} satisfies Meta<typeof Route>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {};
ts
import preview from '../.storybook/preview';

// ๐Ÿ‘‡ Route file is part of the app route tree
import { Route } from './routes/_authenticated/settings/profile';

const meta = preview.meta({
  parameters: {
    tanstack: {
      router: {
        // ๐Ÿ‘‡ Storybook walks up the tree to root and duplicates the full route tree,
        //    so parent layouts (e.g. the authenticated shell) also render.
        route: Route,
        path: '/settings/profile',
        // ๐Ÿ‘‡ Stub out any parent route guards so the story can render standalone.
        routeOverrides: {
          '/_authenticated': { beforeLoad: () => {} },
        },
      },
    },
  },
});

export const Default = meta.story();