Skip to main content
The ZiggyVue plugin integrates Ziggy into Vue applications, making the route() function available throughout your Vue components via the global $route property and composition API.

Installation

Vue 3

Vue 2

Plugin API

install()

The plugin install method registers Ziggy with your Vue application.

Signature

Parameters

Vue | App
required
The Vue application instance. In Vue 3, this is the app created with createApp(). In Vue 2, this is the Vue constructor.
Config
Optional Ziggy configuration object that will be used as the default config for all route() calls.Properties:
  • url: Application URL
  • port: Application port (or null)
  • defaults: Default parameter values
  • routes: Route definitions object
  • location: Override current location (for SSR)

Examples

Usage in Components

Vue 3 - Options API

The route() function is available as this.$route() in component methods:

Vue 3 - Composition API

With Vue 3, the plugin provides route() via inject():

Vue 2

In Vue 2, the plugin adds route() as a global method via mixin:

Advanced Usage

Route Parameters

Relative URLs

Current Route Checking

Checking Route Existence

Accessing Route Parameters

How It Works

Vue 3 Implementation

For Vue 3 (version > 2), the plugin:
  1. Wraps the route() function with the provided options as the default config
  2. Adds it to app.config.globalProperties.route for Options API access
  3. Provides it via app.provide('route') for Composition API access with inject()

Vue 2 Implementation

For Vue 2, the plugin uses a global mixin to add the route() method to all components:

Configuration Precedence

The plugin uses configuration in this order (highest to lowest priority):
  1. Per-call config: this.$route('posts.show', 1, true, customConfig)
  2. Plugin options: app.use(ZiggyVue, options)
  3. Global Ziggy variable
  4. #ziggy-routes-json script tag

Server-Side Rendering (SSR)

For SSR, pass configuration including a custom location object:
This ensures route().current() and route().params work correctly during SSR.

TypeScript Support

The plugin is fully typed for TypeScript users:

Component Type Definitions

For TypeScript components with Options API:
For Composition API:

Plugin Definition

The complete plugin source code:

See Also