biome-no-router-push-plugin
v1.0.1
Published
Biome GritQL plugin that flags router.push() and suggests using router.navigate() instead
Maintainers
Readme
No Router Push
A Biome GritQL plugin that flags uses of router.push() and suggests using router.navigate() instead.
Why
router.push() can cause several issues in React Native applications, particularly when navigating between views in a stack navigator:
- Double navigation: Rapid or concurrent calls to
router.push()can trigger the same navigation twice, pushing duplicate screens onto the stack. - Race conditions: In async flows (e.g., after login or data submission),
router.push()may fire before the navigation state has fully settled, leading to unexpected behavior. - Inconsistent stack state:
router.push()does not always respect the current stack context, which can result in screens being added to the wrong navigator or in an inconsistent order.
Using router.navigate() avoids these pitfalls and provides more predictable navigation behavior.
Plugin
language js
`$obj.push` where {
$obj <: `router`,
register_diagnostic(
span = $obj,
message = "Use router.navigate() instead of router.push()"
)
}Installation
npm install -D biome-no-router-push-plugin
# or
bun add -d biome-no-router-push-pluginThen add the plugin to your biome.json:
{
"plugins": ["./node_modules/biome-no-router-push-plugin/no_router_push.grit"]
}Examples
Flagged
const router = useRouter();
router.push("/dashboard"); × Use router.navigate() instead of router.push()Clean
const router = useRouter();
router.navigate("/dashboard");