Skip to main content

Overview

Ziggy’s route() function works like Laravel’s route() helper—you can pass it the name of a route, and the parameters you want to pass to the route, and it will generate a URL.

Function Signature

The route() function accepts up to four parameters:

Parameters

string
The name of the Laravel route you want to generate a URL for.
string | number | array | object
Route parameters to substitute into the route’s URI template. Can be passed as:
  • A single value (string or number)
  • An array of values
  • An object with parameter names as keys
boolean
default:"true"
Whether to include the URL origin (domain) in the generated URL. Set to false to generate a relative path.
object
Ziggy configuration object. When using the @routes Blade directive, this is available globally and doesn’t need to be passed.

Return Value

The route() function returns:
  • String: A fully-formed URL when called with a route name
  • Router instance: A Router class instance when called with no arguments, providing access to additional methods like current(), has(), and the params property

Basic Usage

Generate a simple URL:
Generate a relative URL:

With Route Parameters

Working with the Router Class

When called without arguments, route() returns a Router instance:

Practical Examples

HTTP Request with Axios

Form Actions

Error Handling

If you pass a route name that doesn’t exist in your route list, Ziggy will throw an error:
When using the @routes Blade directive, Ziggy’s configuration is available globally. If you’re importing Ziggy manually (e.g., in a SPA), you’ll need to pass the configuration as the fourth parameter.

Next Steps

Route Parameters

Learn how to pass parameters to routes

Query Parameters

Add query strings to your URLs