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.
ziggy:generate --types) improve developer experience, especially in large codebases, by providing autocompletion and compile-time route validation.tightenco/ziggy).@routes Blade directive in layouts (or ziggy:generate for custom paths).ZiggyVue for Vue).Route::name() definitions.route() function.@routes Blade output, which may increase payload size. Mitigated via:
ziggy:generate for SPAs (routes pre-fetched at build time).strictRouteNames may break builds if route names are misspelled, but this is a feature, not a bug—tradeoff for safety.@routes Blade directive or ziggy:generate is preferred.ziggy:generate).useRoute for React, ZiggyVue for Vue).slug instead of id)? Ziggy supports this out of the box.ziggy:generate command integrates with these tools for optimal setup.ZiggyVue plugin for global route() access or inject in <script setup>.useRoute hook; works with Next.js, Gatsby, or CRA.route() function directly.route() function available after @routes Blade directive.ziggy-js) for cleaner imports.ziggy:generate can pre-fetch routes for build-time inclusion.route() calls./posts/1 with route('posts.show', 1).ziggy:generate) and integrate with your framework’s routing system.ZiggyVue or React’s useRoute.route().ziggy:generate --types) for compile-time safety.strictRouteNames in TypeScript for stricter validation.composer require tightenco/ziggy
npm install ziggy-js # Optional: for TypeScript or custom builds
@routes to your main layout file (e.g., resources/views/layouts/app.blade.php):
@routes
ziggy-js and add ZiggyVue to your app.useRoute hook.route() generates correct URLs for critical paths.slug instead of id).php artisan ziggy:generate --types
Add type declarations to your tsconfig.json or .d.ts files.@routes output).@routes output by default. Mitigate with filtering or ziggy:generate.route() helper.strictRouteNames in TypeScript).route().current()).ziggy:generate for SPAs).route().current() to inspect current route.route().params to inspect URL parameters.@routes: Minimal overhead; routes are rendered once per page. Impact negligible unless route list is extremely large (>1000 routes).ziggy:generate): Routes are pre-fetched at build time; no runtime overhead.admin.* routes from SPAs).| Scenario | Impact | Mitigation Strategy |
|---|---|---|
| Route name typo in JavaScript | Broken links | Enable strictRouteNames in TypeScript. |
| Route definition changed in Laravel | Stale URLs in frontend | Test critical paths after route changes. |
Cached @routes output |
Outdated routes | Invalidate cache or use ziggy:generate. |
| Complex dynamic routes | URL generation mismatches | Test edge cases (e.g., optional parameters). |
How can I help you explore Laravel packages today?