tightenco/ziggy
Use your Laravel named routes in JavaScript with a route() helper that mirrors Laravel's own route() function.
Repository Health
Technical Analysis
Ziggy exports your Laravel application’s named routes to JavaScript so front-end code can generate URLs the same way Blade and PHP controllers do — route('posts.show', 1) instead of hardcoding path strings. It ships a @routes Blade directive that makes the route() function and your route list globally available in any page, or a ziggy:generate Artisan command plus an installable ziggy-js NPM package for SPA/separate-repo setups that import the function explicitly. It supports route parameters (positional, named, and query), Laravel’s route-model binding (including custom route keys), default parameter values, and full TypeScript type generation for route-name and parameter autocompletion — making the JS side of a Laravel app immune to route-URL drift when routes change in PHP.
What You Get
- A
route()JavaScript function that mirrors Laravel’s PHProute()helper, supporting positional, named, and query parameters - A
@routesBlade directive that makesroute()and the full route configuration globally available in any page’s bundled JavaScript - Route-model binding support, including custom route-key names (e.g.
sluginstead ofid) and scoped bindings - A
ziggy:generateArtisan command and companionziggy-jsNPM package for SPA or separate-repo setups where routes must be explicitly imported - Full TypeScript type definitions plus a
ziggy:generate --typescommand for route-name and parameter autocompletion, with optional strict route-name type checking
Common Use Cases
- Building links and API calls in Vue, React, or vanilla JS front-ends that stay correct automatically when Laravel route definitions change
- Checking the current route in JavaScript (
route().current()) to drive active-nav-link styling or client-side routing decisions - Generating URLs with route-model binding directly from JS objects returned by an API, without manually constructing the URL string
- Type-safe route usage in TypeScript projects, with autocomplete for valid route names and their required parameters
Under The Hood
Architecture - Ziggy has two halves that share a common route-configuration format: a PHP side (a Laravel package registering the @routes Blade directive and ziggy:generate Artisan command) that introspects the application’s route collection and serializes it — URI, HTTP methods, domain, and route-model-binding keys — into a JS-consumable object, and a JavaScript side (published as ziggy-js on NPM, TypeScript source) implementing the route() function and Router class that consumes that configuration to build URLs, match the current route, and manage query/route parameters. The @routes directive path injects the config and function inline as global JS; the manual-import path (ziggy:generate writing resources/js/ziggy.js) is for SPA or separate-frontend-repo setups. Tech Stack - A JavaScript/TypeScript client library (50% JS, ~7% TypeScript in the repo) paired with a PHP Laravel package (~43%) for the server-side route introspection and Blade/Artisan integration; distributed both via Composer (tightenco/ziggy) and NPM (ziggy-js) so the client half can be installed independently of the PHP half when routes are generated to a static file. Code Quality - GitHub Actions CI runs the test suite on every push; the project has shipped 84 tagged releases across nearly a decade with a stable, backward-compatible API evolution from v0.x through the current v2.6, and TypeScript type definitions are maintained and versioned alongside the JS implementation rather than as an afterthought. API Design - The route() function deliberately mirrors Laravel’s own PHP route() helper signature and behavior (parameter arrays vs. objects, default values, query-parameter handling, even boolean-to-integer query encoding), so any developer already familiar with Laravel routing has near-zero new API surface to learn on the JS side; optional strict TypeScript route-name checking is opt-in via a TypeConfig interface extension rather than a breaking default.
Used by 4 apps in this directory
Financial Freedom
Invoicing Finance
Own your financial data with a self-hosted, privacy-first budgeting app that replaces Mint and YNAB.
Mixpost
Marketing · Social Media
Self-host your own social media scheduler and publish to 11 platforms without subscriptions or data lock-in.
solidtime
Productivity · Invoicing Finance
Modern open-source time tracker for freelancers and agencies with invoicing, multi-org support, and Toggl/Clockify migration built in.
Yaffa
Invoicing Finance
Self-hosted personal finance app for long-term financial planning with AI-powered transaction parsing and investment tracking.