tightenco/ziggy

Use your Laravel named routes in JavaScript with a route() helper that mirrors Laravel's own route() function.

Library
Composer
vv2.6.4
4,315stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity88
Maintenance88
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture75
Code Quality78
Innovation68
Learning Curve82

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 PHP route() helper, supporting positional, named, and query parameters
  • A @routes Blade directive that makes route() and the full route configuration globally available in any page’s bundled JavaScript
  • Route-model binding support, including custom route-key names (e.g. slug instead of id) and scoped bindings
  • A ziggy:generate Artisan command and companion ziggy-js NPM package for SPA or separate-repo setups where routes must be explicitly imported
  • Full TypeScript type definitions plus a ziggy:generate --types command 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search