Ziggy provides a JavaScript `route()` function that seamlessly integrates with Laravel's named routes, enabling consistent URL generation in frontend applications. The current stable version is 2.6.2, and the package maintains an active release cadence with frequent patch and minor updates, reflecting ongoing development and support. Its core differentiator lies in its ability to dynamically expose Laravel's PHP-defined routes to the JavaScript environment via a Blade directive, eliminating the need to hardcode URLs or duplicate routing logic. This integration includes support for advanced Laravel features such as route-model binding, automatic handling of query parameters, and robust TypeScript definitions for a type-safe development experience. Ziggy aims to simplify the development of single-page applications (SPAs) and traditional frontend projects by ensuring that frontend routing logic remains synchronized with the backend.
npm install ziggy-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use Ziggy's `route()` function to generate URLs for Laravel named routes in JavaScript, including handling parameters, multiple parameters, query strings, and basic route model binding. It simulates the `window.Ziggy` global configuration that Laravel injects.
Use the `except` or `only` options with the `@routes` Blade directive (e.g., `@routes(['only' => ['web.*']])`) or the `php artisan ziggy:generate` command to explicitly control which routes are published. Utilize route groups for more granular control.
Test your application's routes involving complex query parameters after upgrading to v2.6.0. Most common use cases should be unaffected, but review if you encounter unexpected URL structures.
Run `php artisan ziggy:generate --json` to output the route configuration to a JSON file. Import this file into your frontend application and initialize Ziggy's `route()` function with it: `import { route } from 'ziggy-js'; import Ziggy from '@/ziggy.json'; route.setZiggy(Ziggy);`Upgrade Ziggy to version 2.6.0 or higher to leverage route model binding functionality in your JavaScript routes. Ensure your Laravel backend is also up-to-date to fully support model binding features.
Ensure `@routes` is included in your main Blade layout file (e.g., `app.blade.php`) before any JavaScript that uses Ziggy, typically within the `<head>` or at the start of `<body>`.
For ES Module environments, use `import { route } from 'ziggy-js';`. If using a bundler, ensure your configuration correctly handles ES Modules. If your project strictly uses CommonJS, consider transpilation or adjusting your build setup as `ziggy-js` is primarily designed for ESM.Double-check the route name against your Laravel `web.php` or `api.php` files. Verify your `php artisan ziggy:generate` command or `@routes` Blade directive parameters (`except`, `only`, `group`) are not inadvertently excluding the required route.
No dependency data recorded yet.