* Adds consistency to ESLint rules. * Fixes lint errors. * Fixes manifest. * Adds missing title. * Fixes copy / paste error. Co-authored-by: Lee Robinson <me@leerob.io> * Update errors/no-script-in-document.md Co-authored-by: Lee Robinson <me@leerob.io> * Update errors/no-sync-scripts.md Co-authored-by: Lee Robinson <me@leerob.io> * Updates a couple of rule descriptions. * Adds redirects. * Fixes unit tests. * Removes duplicated section. * Updates `no-before-interactive-script-outside-document` description. * Fixes lint. * Fixes integration tests. * Adds description to `no-before-interactive-script-outside-document` documentation. * Removes `link-passhref` from rules list. * Updates remaining `pages/_middleware.js` references. * Adds consistancy to messaging in new `no-styled-jsx-in-document` rule. * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Lee Robinson <me@leerob.io> Co-authored-by: Tim Neutkens <tim@timneutkens.nl> Co-authored-by: JJ Kasper <jj@jjsweb.site>
1.5 KiB
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 in order 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:
function Home() {
return (
<div>
<a href="/about">About Us</a>
</div>
)
}
After:
import Link from 'next/link'
function Home() {
return (
<div>
<Link href="/about">
<a>About Us</a>
</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
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.
{
"rules": {
"@next/next/no-html-link-for-pages": ["error", "packages/my-app/pages/"]
}
}