Skip to main content

Installation

Ziggy includes a Vue plugin that makes the route() 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, use route() directly in your templates:

Vue 3 Composition API

The ZiggyVue plugin provides the route() 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 registers route() as a global method:

Complete Examples

Form Submission

Data Fetching with Composables

TypeScript Support

To use Ziggy with TypeScript in Vue, you need to declare the route property on Vue’s component interface.

Vue 3 TypeScript Declaration

Create a ziggy.d.ts file in your project:
This enables TypeScript to recognize 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:
Then your routes will have full autocomplete:

Plugin Implementation

The ZiggyVue plugin is implemented as follows:
The plugin automatically passes the config you provide to .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 for ComponentCustomProperties 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