Dongkyuuuu / eslint-plugin-typesafe-next-route

Eslint plugin for type-safe routing within Next.js

Home Page:https://www.npmjs.com/package/eslint-plugin-typesafe-next-route

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-plugin-typesafe-next-route

Eslint plugin for type-safe routing within Next.js

Installation

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

Usage

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 ['/']

This plugin is alpha yet

βœ… default routing with next/link

πŸ§‘β€πŸ’» default routing with next/router

πŸ§‘β€πŸ’» query string routing

πŸ§‘β€πŸ’» dynamic routing

πŸ§‘β€πŸ’» check typescript env

About

Eslint plugin for type-safe routing within Next.js

https://www.npmjs.com/package/eslint-plugin-typesafe-next-route

License:MIT License


Languages

Language:JavaScript 100.0%