tightenco/ziggy
Ziggy brings Laravel’s named routes to JavaScript with a route() helper that mirrors Laravel’s. Generate URLs client-side with parameters, model binding, and TypeScript support, and filter which routes are exposed. Works with Vue, React, SPAs, and separate repos.
composer require tightenco/ziggy.@routes Blade directive (e.g., in your main layout) before your application’s JavaScript bundle—this exposes the globally available route() helper and config.route() in JS exactly like Laravel’s PHP helper: route('posts.show', { id: 1 }).php artisan ziggy:generate --types to generate route-specific type declarations, and declare var route: typeof routeFn globally if needed.@routes + route() directly in Blade-templated JS—no manual imports needed.php artisan ziggy:generate, then import route and Ziggy from ziggy-js (alias in vite.config.js for cleaner imports).use(ZiggyVue) in app entry; inject route via inject('route') in <script setup>.useRoute() hook; optionally pass Ziggy config explicitly.route('posts.show', { post: 42 }).slug) and id fallback._query to avoid collisions).Ziggy::map() in config/ziggy.php, using only, except, or groups.@routes embeds all routes in HTML by default—audit exposure in production (e.g., avoid exposing admin routes).route().params are always strings—convert id to Number() before API calls.route() with no arguments returns the Router instance—don’t accidentally call route().current() as a URL generator; use route() for URLs.@routes, always pass Ziggy config to route() or framework helpers (e.g., useRoute(Ziggy) in React)—silent failures occur otherwise.strictRouteNames: true via module augmentation to catch typos at compile time—but ensure type generation includes all expected routes.ziggy:generate or restart dev server if watching isn’t triggering rebuilds.How can I help you explore Laravel packages today?