Installation
Ziggy includes a Vue plugin that makes theroute() helper available throughout your Vue application—in templates, component scripts, and the Options API.
Basic Setup with @routes
If you’re using the@routes Blade directive, Ziggy’s config is available globally. Simply install the plugin:
Setup Without @routes
If you’re not using@routes, import and pass Ziggy’s configuration to the plugin:
Usage in Templates
Once the plugin is installed, useroute() directly in your templates:
Vue 3 Composition API
The ZiggyVue plugin provides theroute() function via Vue’s dependency injection system.
Using inject() with <script setup>
In Vue 3’s <script setup>, use inject() to access the route() function:
Standard Composition API
Vue 2 Support
ZiggyVue automatically detects Vue 2 and registersroute() as a global method:
Complete Examples
Navigation Component
Form Submission
Data Fetching with Composables
TypeScript Support
To use Ziggy with TypeScript in Vue, you need to declare theroute property on Vue’s component interface.
Vue 3 TypeScript Declaration
Create aziggy.d.ts file in your project:
route() in your templates and Options API components without type errors.
Using with <script setup lang="ts">
Typed Route Parameters
For full type safety with route names and parameters, generate Ziggy’s type definitions:Plugin Implementation
The ZiggyVue plugin is implemented as follows:.use(ZiggyVue, config) to every route() call, so you don’t need to pass it manually.
Troubleshooting
route is not defined in templates
Ensure you’ve installed the ZiggyVue plugin:
inject() returns undefined
Make sure the plugin is installed before mounting your app, and that you’re using Vue 3.
TypeScript errors in templates
Add the module declaration forComponentCustomProperties as shown in the TypeScript section above.
Next Steps
TypeScript
Set up full type safety and autocompletion
React
Use Ziggy with React instead
Route Helper
Learn all route() function capabilities
JavaScript Frameworks
General framework integration guide