All skills
sergiodxa avatar

/frontend-react-router-best-practices

@9da9532

React Router performance and architecture patterns. Use when writing loaders, actions, forms, routes, or working with React Router data fetching. Triggers on tasks involving React Router routes, data loading, form handling, or route organization.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-react-router-best-practices

This session only. Nothing lands on disk.

ruleslink-prefetch-intent.md

≈574 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Link Prefetch Intent

Use prefetch="intent" on links for faster perceived navigation.

Why

  • Prefetches route data on hover/focus (before click)
  • Makes navigation feel instant
  • Only loads data when user shows intent
  • Better than prefetch="render" (loads immediately) for large pages

Pattern

import { Link } from "react-router";

<Link to="/dashboard" prefetch="intent">
  Dashboard
</Link>;

Prefetch Options

Value When Prefetches Use Case
"none" Never Rarely visited links
"intent" Hover/focus Most navigation links
"render" On render Critical next steps
"viewport" When visible Link lists

Examples from Codebase

// Navigation links
<Link to="/dashboard" prefetch="intent">
  Dashboard
</Link>

// Login/auth links
<Link to="/login" className="font-medium" prefetch="intent">
  Log in
</Link>

// Notification items
<Link
  to={notification.link}
  prefetch="intent"
  className="block p-3 hover:bg-neutral-50"
>
  {notification.title}
</Link>

// Pagination
<Link
  to={`?page=${page + 1}`}
  prefetch="intent"
  className="px-3 py-2"
>
  Next
</Link>

With LinkButton Component

The LinkButton component should also support prefetch:

<LinkButton to="/settings" prefetch="intent">
  Settings
</LinkButton>

When NOT to Use prefetch="intent"

// External links - can't prefetch
<a href="https://example.com">External</a>

// Very heavy pages - might waste bandwidth
<Link to="/huge-report" prefetch="none">
  Generate Report
</Link>

// User might not navigate (e.g., in long lists)
<Link to={`/items/${item.id}`} prefetch="viewport">
  {item.name}
</Link>

With NavLink for Active States

import { NavLink } from "react-router";

<NavLink
  to="/dashboard"
  prefetch="intent"
  className={({ isActive }) =>
    isActive ? "text-accent-600 font-medium" : "text-neutral-600"
  }
>
  Dashboard
</NavLink>;

Prefetch with State

<Link to="/checkout" prefetch="intent" state={{ from: "cart" }}>
  Proceed to Checkout
</Link>

Source: SKILL.md on GitHub

2 warnings16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive set of developer guidelines and best practices for building React Router applications. It emphasizes performance, type safety, and security measures like input validation (Zod), safe redirects, and CSRF protection (Sec-Fetch). No malicious code, obfuscation, or data exfiltration patterns were detected.

  • Socket16d

    1 alert: gptSecurity

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    56/56 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 9da9532. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-react-router-best-practices