Skip to main content

Overview

Route parameters allow you to substitute dynamic values into your route URIs. Ziggy supports multiple ways to pass parameters, making it flexible and intuitive to work with Laravel routes in JavaScript.

Single Parameter

For routes with a single parameter, you can pass the value directly:
All three formats produce the same result. Use whichever feels most natural for your use case.

Multiple Parameters

For routes with multiple parameters, you can use arrays or objects:

Array Syntax (Positional)

Parameters are matched to route segments in order:
With arrays, parameter order matters! The first value corresponds to the first route parameter, the second to the second, and so on.

Object Syntax (Named)

Parameters are matched by name, so order doesn’t matter:

Passing Model Objects

Ziggy intelligently extracts parameter values from JavaScript objects representing models:
When you pass an object as a parameter, Ziggy uses route-model binding keys to find the correct value. See Route-Model Binding for more details.

Mixed Arrays with Objects

You can mix primitives and objects when using arrays:

Optional Parameters

Laravel routes can have optional parameters denoted with ?:
Optional parameters can be omitted:

Required Parameters

If you omit a required parameter, Ziggy will throw an error:

Parameter Constraints

Laravel’s route constraints (defined with where()) are enforced by Ziggy:

How Parameter Parsing Works

Ziggy normalizes all parameter formats into a consistent object structure before building the URL:
The _parse() method in Router.js handles parameter normalization:
  1. Primitive values (strings/numbers) are wrapped in an array
  2. Arrays are transformed into objects by mapping values to parameter names in order
  3. Objects are checked for route-model binding keys
  4. Default parameters from URL::defaults() are merged in

Extra Parameters Become Query Parameters

Parameters that don’t match route segments are automatically added as query parameters:
Learn more about this behavior in Query Parameters.

Best Practices

Generate Ziggy’s TypeScript definitions for autocomplete and type checking:

Next Steps

Query Parameters

Add query strings to generated URLs

Route-Model Binding

Work with Laravel’s route-model binding