Open-source project
tighten/ziggy avatar
tighten/ziggy

Ziggy: how Laravel named routes reach JavaScript

Use your Laravel routes in JavaScript.

4,317 stars273 forksJavaScriptMIT

At a glance

What is it?
Ziggy serialises your Laravel route table into the page and rebuilds Laravel's route() helper in JavaScript. It is a good fit when the front end is one Laravel app and a poor fit when routes live elsewhere.
Who is it for?
Adopt Ziggy when your JavaScript is built and shipped by the same Laravel application that owns the routes, and when the front end composes its own URLs rather than receiving them from Blade. Skip it when the front end is a separate deployment that fetches URLs over HTTP, when a generated configuration file would go stale between deploys, or when you cannot accept the full route list in the HTML.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 8 days ago.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • tighten/ziggy4,317 ★ · +0
Star history
Repository2026-09-232026-11-22
tighten/ziggy4.3k4.3k

0 Stars in the last 60 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The route table is printed into every page by @routes

Named Laravel routes break the moment a JavaScript file has to hardcode a path. Change a route parameter name and the front end still asks for the old URL. Ziggy removes that duplication by shipping the route list with the HTML and rebuilding the generator on the client.

Install it as a Composer package inside the Laravel app, then add the @routes Blade directive to the main layout ahead of the application's JavaScript. The directive writes the route list into the page and installs route() as a global function, so any script loaded after it can build URLs. The same list also feeds the JavaScript Router class used for route().current() and route().params.

That design has one consequence worth stating early. Your route names, URI patterns and parameter names become part of the page source, readable by anyone who views it. Ziggy gives you include, exclude and group filters to shape that list, and the documentation is explicit that the output includes all routes and their parameters by default.

composer require tightenco/ziggy, then call route() by name

The install is one Composer command, with no JavaScript build step and no bundler configuration for the basic case.

bash
composer require tightenco/ziggy

After the directive is in place, a route named on the PHP side resolves on the client with the same name and the same parameters.

php
Route::get('posts', fn (Request $request) => /* ... */)->name('posts.index');
js
route('posts.index'); // 'https://ziggy.test/posts'

Route parameters can be passed positionally, as an array, or as an object keyed by parameter name, and all three forms produce the same URL. Extra keys that match no route parameter are appended as a query string. That single behaviour covers most calls, so a front end rarely needs a custom URL builder on top of it.

_query is the escape hatch when a query key collides with a route parameter

The rule that unmatched keys become query parameters has an obvious edge case. If the route declares {event} and you also want an event query filter, both want the same key. Ziggy resolves this with a reserved _query key: nested keys there are forced into the query string even when they share a name with a route parameter.

js
route('venues.events.show', {
    venue: 1,
    event: 2,
    _query: {
        event: 3,
        page: 5,
    },
});
// 'https://ziggy.test/venues/1/events/2?event=3&page=5'

Booleans follow Laravel and are encoded as integers, so draft: false becomes draft=0 and overdue: true becomes overdue=1. This is worth knowing before you write a predicate against the query string on the client: the value you read back is a string, not a boolean.

Router answers current(), has() and params, and params are always strings

Calling route() with no arguments returns an instance of the Router class rather than a URL, which is how the client learns where it is. current() matches against the current window URL, supports wildcard names such as 'events.*', and can also verify parameter values, including query string keys.

js
// Laravel route called 'events.index' with URI '/events'
// Current window URL is https://ziggy.test/events

route().current();               // 'events.index'
route().current('events.index'); // true
route().current('events.*');     // true
route().current('events.show');  // false

has() answers whether a named route exists at all, which is useful when a front end ships against a newer or older route table. params returns the decoded parameters, and the documentation flags a constraint plainly: values retrieved with route().params will always be returned as strings. Any comparison against a numeric identifier needs a cast on your side.

Route-model binding lets you pass whole model objects

A plain object is enough to build a URL. Ziggy looks at the keys registered as route-model binding keys for that route, and falls back to the object's id key when nothing is registered. A model that overrides getRouteKeyName to return 'slug' therefore lets you pass the model straight from an axios response instead of extracting the primary key by hand.

js
const post = { id: 1, title: 'Ziggy Stardust' };

return axios.get(route('posts.show', post)).then((response) => response.data);

The catch is that this only works for keys the backend registered. If your model serialises to the client with a field the route does not use, Ziggy has no way to know it, and the object's id becomes the parameter value whether you wanted that or not. The mapping is defined on the PHP model, not in JavaScript, so a rename on the server is what breaks the client here.

Separate front ends pay for the global with a generated config

The @routes directive covers the single-app case. When the JavaScript lives in its own repository or is loaded as an SPA, the README documents generating and importing Ziggy's configuration instead, and the npm package is published separately as ziggy-js, with a build entry point at ./dist/index.js and type declarations shipped from src/js/index.d.ts.

For framework code, the two halves are exported separately: the generated route list as configuration, and the route() function to import from the package. That means a hand-rolled import path in your bundler, and a build step that has to run whenever routes change.

This is where Ziggy stops being a one-command install. If your front end and your Laravel app deploy on separate schedules, the generated file can be stale at exactly the moment a route changes.

The alternative is a URL passed from PHP, at the cost of losing route names in the client

The usual alternative is not another package. It is to skip the client-side route table entirely and emit URLs from Blade, letting Laravel's own route() helper produce them and passing the results to JavaScript as data.

The difference in approach is real. Ziggy duplicates the route table into the browser and re-implements the generator, so the client keeps route names and can build a URL it was never handed. Passing URLs from Blade does no duplication and publishes no route names, but it only covers the URLs a developer thought to emit, and each screen needs its own wiring.

Choose Ziggy when the front end composes its own URLs in loops, conditionals or library code. Choose Blade-emitted URLs when the set of links is small and fixed and you would rather not hand a route inventory to every visitor. Ziggy ships under the MIT licence and its last push was on 2026-10-10.

Editorial conclusion

Adopt Ziggy when your JavaScript is built and shipped by the same Laravel application that owns the routes, and when the front end composes its own URLs rather than receiving them from Blade. Skip it when the front end is a separate deployment that fetches URLs over HTTP, when a generated configuration file would go stale between deploys, or when you cannot accept the full route list in the HTML. Before anything else, check which routes the @routes directive emits in production and exclude any you would not hand to a visitor. Then confirm that every model passed to route() serialises with the key its route actually uses. The current release is v2.6.5, published on 2026-10-10, and the MIT licence covers both the Composer package and the ziggy-js npm build.

Frequently asked questions

how to install ziggy

Run composer require tightenco/ziggy inside your Laravel app, then add the @routes Blade directive to your main layout before your application's JavaScript. The route() helper becomes globally available to scripts loaded after it.

how to set up ziggy

Beyond the Composer install, @routes prints a list of all your application's routes and their parameters into the page HTML. Use Ziggy's route filtering to include or exclude routes, or to show different routes on different pages.

how to use ziggy in laravel

Pass a route name to route() with its parameters, positionally, as an array or as an object. Arguments that match no route parameter are appended as query parameters, and route().current(), route().has() and route().params tell the client where it is.

Official sources

  1. Issues
  2. License: MIT
  3. README
  4. Releases
  5. tighten/ziggy on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/tighten-ziggy.svg)](https://hysenlabs.com/projects/tighten-ziggy)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/tighten-ziggy.svg)](https://hysenlabs.com/projects/tighten-ziggy)

Was this useful?