Eslint plugin for type-safe routing within Next.js
MIT License
Eslint plugin for type-safe routing within Next.js
This plugin is deprecated. Next.js support statically typed links at 13.2 version.
You'll first need to install ESLint:
npm i eslint --save-dev # or
yarn add eslint -D
Next, install eslint-plugin-typesafe-next-route
:
npm install eslint-plugin-typesafe-next-route --save-dev # or
yarn add eslint-plugin-typesafe-next-route -D
Add typesafe-next-route
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": ["typesafe-next-route"]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"typesafe-next-route/typesafe-next-link": ["error", { "routes": ["/", "/a"] }]
}
}
then below code catch error
+<Link href="/">go Home</Link>
+<Link href="/a">go A</Link>
-<Link href="/b">go B</Link> # error
-<Link href="/foo">go Far</Link> # error
default of routes is
['/']
default routing with next/link
default routing with next/router
query string routing
dynamic routing
check typescript env