router-core/navigation

Implements type-safe navigation in TanStack Router using Link, useNavigate, preloading, and blocking.

1.4k|34|Updated Mar 7, 2024
One-click install
npx skills add https://github.com/mehdibha/dotUI --skill router-core-navigation-mehdibha
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: router-core/navigation
Source: https://github.com/mehdibha/dotUI/tree/main/.claude/skills/tanstack-router-navigation
Command: npx skills add https://github.com/mehdibha/dotUI --skill router-core-navigation-mehdibha

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router.

What problem does it solve? Navigating between routes in a React app often breaks type safety, loses search params, or mishandles relative paths and unsaved-changes warnings. This Skill provides correct, type-safe patterns for every navigation scenario in TanStack Router. ## Core Features & Use Cases - Type-Safe Links and Navigation: Use Link, useNavigate, Navigate, and router.navigate with params, search functions, and relative paths via the from option. - Preloading and Performance: Configure intent, viewport, or render preloading strategies with preloadDelay and stale-time control for faster perceived navigation. - Navigation Blocking and UX Extras: Guard unsaved forms with useBlocker, build reusable linkOptions and custom createLink components, and restore scroll positions. - Use Case: When building a dashboard with nested routes, use linkOptions arrays for the nav bar, activeProps for highlighting, and useBlocker to warn users leaving a dirty edit form. ## Quick Start Show me how to add a type-safe Link to a dynamic post route with active styling and hover preloading in my TanStack Router app.

Frequently Asked Questions about router-core/navigation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a type-safe Link with dynamic params in TanStack Router?▼

Pass the route path with a $ segment to the to prop and supply values via the params object, for example to="/posts/$postId" with params={{ postId }}. Never interpolate values into the to string, as that breaks type safety and param encoding.

When should I use useNavigate vs Link in TanStack Router?▼

Use Link for anything the user clicks, since it renders a real anchor with href, accessibility, and preloading. Reserve useNavigate for programmatic side-effect navigation, such as redirecting after a form submission or async action.

How does preloading work in TanStack Router?▼

Set defaultPreload to intent, viewport, or render on the router, or per Link with the preload prop. Preloaded data stays fresh for 30 seconds by default; set defaultPreloadStaleTime to 0 when an external cache like TanStack Query controls freshness.

How do I block navigation when a form has unsaved changes?▼

Use the useBlocker hook with a shouldBlockFn that returns true when the form is dirty. Add withResolver: true to get proceed, reset, and status for rendering a custom confirmation dialog instead of the native confirm.

Why does my relative Link with ".." navigate to the wrong route?▼

Without the from option, relative paths like ".." resolve from the root route instead of the current one. Pass from={Route.fullPath} so relative navigation resolves against the current route and stays type-safe.

Why do my search params disappear when navigating with Link?▼

Passing search as a plain object replaces all existing search params. Use the function form, search={(prev) => ({ ...prev, page: 2 })}, to preserve current params while updating specific values.