Buckets:
| --- | |
| title: No HTML link for pages | |
| --- | |
| > Prevent usage of `<a>` elements to navigate to internal Next.js pages. | |
| ## Why This Error Occurred | |
| An `<a>` element was used to navigate to a page route without using the `next/link` component, causing unnecessary full-page refreshes. | |
| The `Link` component is required to enable client-side route transitions between pages and provide a single-page app experience. | |
| ## Possible Ways to Fix It | |
| Make sure to import the `Link` component and wrap anchor elements that route to different page routes. | |
| **Before:** | |
| ```jsx filename="pages/index.js" | |
| function Home() { | |
| return ( | |
| <div> | |
| <a href="/about">About Us</a> | |
| </div> | |
| ) | |
| } | |
| ``` | |
| **After:** | |
| ```jsx filename="pages/index.js" | |
| import Link from 'next/link' | |
| function Home() { | |
| return ( | |
| <div> | |
| <Link href="/about">About Us</Link> | |
| </div> | |
| ) | |
| } | |
| export default Home | |
| ``` | |
| ### Options | |
| #### `pagesDir` | |
| This rule can normally locate your `pages` directory automatically. | |
| If you're working in a monorepo, we recommend configuring the [`rootDir`](/docs/pages/api-reference/config/eslint#specifying-a-root-directory-within-a-monorepo) setting in `eslint-plugin-next`, which `pagesDir` will use to locate your `pages` directory. | |
| In some cases, you may also need to configure this rule directly by providing a `pages` directory. This can be a path or an array of paths. | |
| ```json filename="eslint.config.json" | |
| { | |
| "rules": { | |
| "@next/next/no-html-link-for-pages": ["error", "packages/my-app/pages/"] | |
| } | |
| } | |
| ``` | |
| ## Useful Links | |
| - [next/link API Reference](/docs/pages/api-reference/components/link) | |
Xet Storage Details
- Size:
- 1.61 kB
- Xet hash:
- aa87ced33f51e59800c0a4f5b36e572a699b6432f19113d556afe01b2f7877cd
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.