ButtonFilename match componentJsx sort propsMatch navigation routeEnforce Matching useNavigation/useRoute Generic and Import ( match-navigation-route )Require try catch asyncRequire usestate typeValid translation key
Enforce Matching useNavigation/useRoute Generic and Import (match-navigation-route
)
This rule enforces two things inside .tsx
files under src/screens/
:
useNavigation
anduseRoute
must be used with a generic of the formRouteNames.<SCREEN_NAME>
- These hooks must not be imported from
@react-navigation/native
— only local wrappers are allowed
🧩 Rule Type
- Type:
problem
- Category:
Type Safety
- Fixable: No
- Recommended: No
📚 Why Enforce This Rule?
This rule ensures:
- Screens use only their corresponding route types
- Navigation types are explicitly stated
- Hooks are only imported from your app’s local navigation wrapper (not directly from external libraries)
- Misconfigured or missing generics are caught early
✅ Correct Usage
Home.tsx
import { useNavigation, useRoute } from 'src/navigations';const navigation = useNavigation<RouteNames.HOME>();const route = useRoute<RouteNames.HOME>();
❌ Incorrect Usage
Home.tsx
import { useNavigation } from 'src/navigations';// Wrong genericconst navigation = useNavigation<RouteNames.ABOUT>();^^^^^^^^^^^^^// Generic "RouteNames.ABOUT" does not match expected "RouteNames.HOME"// Missing genericconst route = useRoute();^^^^^^^^// You must specify a generic like useRoute<RouteNames.HOME>// Disallowed importimport { useNavigation } from '@react-navigation/native';^^^^^^^^^^^^^^^^^^^^^^^^^^// Do not import "useNavigation" from @react-navigation/native. Use your local wrapper instead.const navigation = useNavigation<RouteNames.HOME>();
📂 Ignored Files
The following are ignored:
- Files outside
src/screens/
- Non-
.tsx
files - Other hooks or identifiers not named
useNavigation
oruseRoute
🔍 When To Enable
Enable this rule when:
- You have a central
RouteNames
object for navigation. - You use a wrapper around
useNavigation
anduseRoute
for type-safe routing. - You want to prevent untyped or mismatched navigation access in screens.
⚙️ Options
This rule does not take any configuration options.