# Fumadocs (Framework Mode, TanStack Start): Validate Links
URL: /docs/tanstack-start/markdown/validate-links
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/markdown/validate-links.mdx

Ensure your links are correct.

## Setup [#setup]

You can use [`next-validate-link`](https://next-validate-link.vercel.app) to validate your links in content files.

> This guide is mainly for **Fumadocs MDX**, see the docs of `next-validate-link` for other setups.

Create a script that scans the routes of your app. `populate` lists the params of your docs route:

```ts title="scripts/lint.ts"
import { type FileObject, printErrors, scanURLs, validateFiles } from 'next-validate-link';
import { source } from '@/lib/source';

const scanned = await scanURLs({
  preset: 'tanstack-start',
  populate: {
    // async collections load the TOC with the content
    'docs/[[..._splat]]': await Promise.all(
      source.getPages().map(async (page) => ({
        value: { _splat: page.slugs },
        hashes: getHeadings(await page.data.load()),
      })),
    ),
  },
});
```

In the same script, validate your content files against the scanned URLs:

```ts title="scripts/lint.ts"
import type { TOCItemType } from 'fumadocs-core/toc';

printErrors(
  await validateFiles(await getFiles(), {
    scanned,
    // check `href` attributes in different MDX components
    markdown: {
      components: {
        Card: { attributes: ['href'] },
      },
    },
    // check relative paths
    checkRelativePaths: 'as-url',
  }),
  true,
);

function getHeadings({ toc }: { toc: TOCItemType[] }): string[] {
  return toc.map((item) => item.url.slice(1));
}

function getFiles() {
  const promises = source.getPages().map(async (page): Promise<FileObject> => ({
    path: page.absolutePath,
    content: await page.data.getText('raw'),
    url: page.url,
    data: page.data,
  }));

  return Promise.all(promises);
}
```

### Running Lint [#running-lint]

To access the `source` object outside of app runtime, configure [Fumadocs MDX Loader](/docs/mdx/loader/bun) for Bun.

Then, run the script to validate links:

```bash
bun ./scripts/lint.ts
```

<Callout title="Node.js Loader">
You might need to configure TypeScript transpiling (or newer version of Node.js), and [Fumadocs MDX Loader](/docs/mdx/loader/node).

Without special reasons, using Bun or [`tsx`](https://github.com/privatenumber/tsx) would be simpler.
</Callout>