Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ziggy Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Use your Laravel routes in JavaScript.

Frequently asked questions about Ziggy
How do I install Ziggy in a Laravel project?
Run `composer require tightenco/ziggy` to install via Composer. Add the `@routes` Blade directive to your main layout file (e.g., `resources/views/layouts/app.blade.php`) before your JavaScript. This injects the `route()` helper globally for all frontend code.
Does Ziggy work with Laravel 10? Are there breaking changes?
Yes, Ziggy is fully compatible with Laravel 10+. The package is actively maintained and tested against the latest Laravel versions. No breaking changes have been introduced for Laravel 10, but always check the [release notes](https://github.com/tighten/ziggy/releases) for minor updates.
Can I use Ziggy with Vue 3 or React 18 in a SPA?
Absolutely. Ziggy works seamlessly with modern SPAs. For Vue 3, use the `ZiggyVue` plugin or inject the `route()` function in `<script setup>`. For React 18, use the `useRoute` hook. For SPAs, generate routes at build time with `ziggy:generate` to avoid bloating HTML.
How do I filter routes to reduce payload size?
Use the `ziggy:routes` configuration in `config/ziggy.php` to include or exclude routes by name or group. For example, exclude admin routes with `'exclude' => ['admin.*']`. This prevents unnecessary routes from being embedded in your HTML or JavaScript bundle.
Will Ziggy work with custom route-model binding keys (e.g., slugs instead of IDs)?
Yes, Ziggy supports custom route-model binding keys out of the box. Simply use the same syntax as Laravel’s `route()` helper in PHP. For example, `route('posts.show', { slug: 'my-post' })` will work if your route is defined as `Route::get('/posts/{slug}', ...)->name('posts.show')`.
How do I generate TypeScript types for Ziggy routes?
Run `php artisan ziggy:generate --types` to generate TypeScript types for your route names and parameters. This creates a `ziggy.d.ts` file in your `resources/js` directory, providing autocompletion and compile-time safety for route names and parameters.
Can Ziggy be used in a monorepo with separate frontend/backend repos?
Yes, Ziggy supports separate repos. Use `ziggy:generate` to export routes to a JSON file (e.g., `routes.json`) in your frontend repo. This file can be imported directly into your JavaScript codebase, ensuring routes stay in sync without coupling repos.
What’s the best way to test Ziggy-generated URLs in JavaScript?
Test Ziggy URLs by comparing them against Laravel’s `url()` helper in PHP. Write unit tests in JavaScript (e.g., with Jest) to verify `route()` outputs match expected paths. For example, assert `route('posts.index')` equals `/posts`. Also test dynamic routes with model binding.
Does Ziggy support Vite or Webpack for optimized builds?
Yes, Ziggy integrates with Vite and Webpack. For Vite, use the `ziggy-js` package (`npm install ziggy-js`) and configure it in your `vite.config.js`. For Webpack, ensure the `@routes` Blade directive is placed before your JavaScript bundle. Both setups allow Ziggy to work with path aliases.
What are the alternatives to Ziggy for Laravel route handling in JavaScript?
Alternatives include manually hardcoding routes (not recommended), using Laravel’s `window.Laravel` global object (limited to basic routes), or custom solutions like `axios` interceptors for URL generation. Ziggy stands out by mirroring Laravel’s `route()` helper exactly, supporting model binding, and offering TypeScript integration.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
boundwize/jsonrecast
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata