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: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?:
Required Parameters
Parameter Constraints
Laravel’s route constraints (defined withwhere()) are enforced by Ziggy:
How Parameter Parsing Works
Ziggy normalizes all parameter formats into a consistent object structure before building the URL:Implementation Details
Implementation Details
The
_parse() method in Router.js handles parameter normalization:- Primitive values (strings/numbers) are wrapped in an array
- Arrays are transformed into objects by mapping values to parameter names in order
- Objects are checked for route-model binding keys
- 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
Use objects for clarity with multiple parameters
Use objects for clarity with multiple parameters
Pass model objects when available
Pass model objects when available
Use TypeScript for parameter safety
Use TypeScript for parameter safety
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