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 URLport: Application port (ornull)defaults: Default parameter valuesroutes: Route definitions objectlocation: Override current location (for SSR)
Examples
Usage in Components
Vue 3 - Options API
Theroute() function is available as this.$route() in component methods:
Vue 3 - Composition API
With Vue 3, the plugin providesroute() via inject():
Vue 2
In Vue 2, the plugin addsroute() 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:- Wraps the
route()function with the provided options as the default config - Adds it to
app.config.globalProperties.routefor Options API access - Provides it via
app.provide('route')for Composition API access withinject()
Vue 2 Implementation
For Vue 2, the plugin uses a global mixin to add theroute() method to all components:
Configuration Precedence
The plugin uses configuration in this order (highest to lowest priority):- Per-call config:
this.$route('posts.show', 1, true, customConfig) - Plugin options:
app.use(ZiggyVue, options) - Global
Ziggyvariable #ziggy-routes-jsonscript tag
Server-Side Rendering (SSR)
For SSR, pass configuration including a customlocation object:
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:Plugin Definition
The complete plugin source code:See Also
- route() Function - Core route helper
- Router Class - Advanced routing features
- React Hook - Using Ziggy in React