.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Mojolicious::Routes::Route 3"
.TH Mojolicious::Routes::Route 3 "2023-03-08" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Mojolicious::Routes::Route \- Route
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Mojolicious::Routes::Route;
\&
\& my $r = Mojolicious::Routes::Route\->new;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Mojolicious::Routes::Route is the route container used by Mojolicious::Routes.
.SH "ATTRIBUTES"
.IX Header "ATTRIBUTES"
Mojolicious::Routes::Route implements the following attributes.
.SS "children"
.IX Subsection "children"
.Vb 2
\& my $children = $r\->children;
\& $r = $r\->children([Mojolicious::Routes::Route\->new]);
.Ve
.PP
The children of this route, used for nesting routes.
.SS "inline"
.IX Subsection "inline"
.Vb 2
\& my $bool = $r\->inline;
\& $r = $r\->inline($bool);
.Ve
.PP
Allow \*(L"under\*(R" semantics for this route.
.SS "parent"
.IX Subsection "parent"
.Vb 2
\& my $parent = $r\->parent;
\& $r = $r\->parent(Mojolicious::Routes::Route\->new);
.Ve
.PP
The parent of this route, usually a Mojolicious::Routes::Route object. Note that this attribute is weakened.
.SS "partial"
.IX Subsection "partial"
.Vb 2
\& my $bool = $r\->partial;
\& $r = $r\->partial($bool);
.Ve
.PP
Route has no specific end, remaining characters will be captured in \f(CW\*(C`path\*(C'\fR.
.SS "pattern"
.IX Subsection "pattern"
.Vb 2
\& my $pattern = $r\->pattern;
\& $r = $r\->pattern(Mojolicious::Routes::Pattern\->new);
.Ve
.PP
Pattern for this route, defaults to a Mojolicious::Routes::Pattern object.
.SH "METHODS"
.IX Header "METHODS"
Mojolicious::Routes::Route inherits all methods from Mojo::Base and implements the following new ones.
.SS "add_child"
.IX Subsection "add_child"
.Vb 1
\& $r = $r\->add_child(Mojolicious::Routes::Route\->new);
.Ve
.PP
Add a child to this route, it will be automatically removed from its current parent if necessary.
.PP
.Vb 2
\& # Reattach route
\& $r\->add_child($r\->find(\*(Aqfoo\*(Aq));
.Ve
.SS "any"
.IX Subsection "any"
.Vb 9
\& my $route = $r\->any;
\& my $route = $r\->any(\*(Aq/:foo\*(Aq);
\& my $route = $r\->any(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->any(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->any(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->any(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->any(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
\& my $route = $r\->any([\*(AqGET\*(Aq, \*(AqPOST\*(Aq] => \*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->any([\*(AqGET\*(Aq, \*(AqPOST\*(Aq] => \*(Aq/:foo\*(Aq => [foo => qr/\ew+/]);
.Ve
.PP
Generate Mojolicious::Routes::Route object matching any of the listed \s-1HTTP\s0 request methods or all.
.PP
.Vb 2
\& # Route with pattern and destination
\& $r\->any(\*(Aq/user\*(Aq)\->to(\*(Aquser#whatever\*(Aq);
.Ve
.PP
All arguments are optional, but some have to appear in a certain order, like the two supported array reference values,
which contain the \s-1HTTP\s0 methods to match and restrictive placeholders.
.PP
.Vb 2
\& # Route with HTTP methods, pattern, restrictive placeholders and destination
\& $r\->any([\*(AqDELETE\*(Aq, \*(AqPUT\*(Aq] => \*(Aq/:foo\*(Aq => [foo => qr/\ew+/])\->to(\*(Aqfoo#bar\*(Aq);
.Ve
.PP
There are also two supported string values, containing the route pattern and the route name, defaulting to the pattern
\&\f(CW\*(C`/\*(C'\fR and a name based on the pattern.
.PP
.Vb 2
\& # Route with pattern, name and destination
\& $r\->any(\*(Aq/:foo\*(Aq => \*(Aqfoo_route\*(Aq)\->to(\*(Aqfoo#bar\*(Aq);
.Ve
.PP
An arbitrary number of key/value pairs in between the route pattern and name can be used to specify route conditions.
.PP
.Vb 2
\& # Route with pattern, condition and destination
\& $r\->any(\*(Aq/\*(Aq => (agent => qr/Firefox/))\->to(\*(Aqfoo#bar\*(Aq);
.Ve
.PP
A hash reference is used to specify optional placeholders and default values for the stash.
.PP
.Vb 2
\& # Route with pattern, optional placeholder and destination
\& $r\->any(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq})\->to(\*(Aqfoo#bar\*(Aq);
.Ve
.PP
And a code reference can be used to specify a \f(CW\*(C`cb\*(C'\fR value to be merged into the default values for the stash.
.PP
.Vb 4
\& # Route with pattern and a closure as destination
\& $r\->any(\*(Aq/:foo\*(Aq => sub ($c) {
\& $c\->render(text => \*(AqHello World!\*(Aq);
\& });
.Ve
.PP
See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "delete"
.IX Subsection "delete"
.Vb 7
\& my $route = $r\->delete;
\& my $route = $r\->delete(\*(Aq/:foo\*(Aq);
\& my $route = $r\->delete(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->delete(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->delete(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->delete(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->delete(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
.Ve
.PP
Generate Mojolicious::Routes::Route object matching only \f(CW\*(C`DELETE\*(C'\fR requests, takes the same arguments as \*(L"any\*(R"
(except for the \s-1HTTP\s0 methods to match, which are implied). See Mojolicious::Guides::Tutorial and
Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Route with destination
\& $r\->delete(\*(Aq/user\*(Aq)\->to(\*(Aquser#remove\*(Aq);
.Ve
.SS "find"
.IX Subsection "find"
.Vb 1
\& my $route = $r\->find(\*(Aqfoo\*(Aq);
.Ve
.PP
Find child route by name, custom names have precedence over automatically generated ones.
.PP
.Vb 2
\& # Change default parameters of a named route
\& $r\->find(\*(Aqshow_user\*(Aq)\->to(foo => \*(Aqbar\*(Aq);
.Ve
.SS "get"
.IX Subsection "get"
.Vb 7
\& my $route = $r\->get;
\& my $route = $r\->get(\*(Aq/:foo\*(Aq);
\& my $route = $r\->get(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->get(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->get(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->get(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->get(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
.Ve
.PP
Generate Mojolicious::Routes::Route object matching only \f(CW\*(C`GET\*(C'\fR requests, takes the same arguments as \*(L"any\*(R"
(except for the \s-1HTTP\s0 methods to match, which are implied). See Mojolicious::Guides::Tutorial and
Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Route with destination
\& $r\->get(\*(Aq/user\*(Aq)\->to(\*(Aquser#show\*(Aq);
.Ve
.SS "has_custom_name"
.IX Subsection "has_custom_name"
.Vb 1
\& my $bool = $r\->has_custom_name;
.Ve
.PP
Check if this route has a custom name.
.SS "has_websocket"
.IX Subsection "has_websocket"
.Vb 1
\& my $bool = $r\->has_websocket;
.Ve
.PP
Check if this route has a WebSocket ancestor and cache the result for future checks.
.SS "is_endpoint"
.IX Subsection "is_endpoint"
.Vb 1
\& my $bool = $r\->is_endpoint;
.Ve
.PP
Check if this route qualifies as an endpoint.
.SS "is_reserved"
.IX Subsection "is_reserved"
.Vb 1
\& my $bool = $r\->is_reserved(\*(Aqcontroller\*(Aq);
.Ve
.PP
Check if string is a reserved stash value.
.SS "is_websocket"
.IX Subsection "is_websocket"
.Vb 1
\& my $bool = $r\->is_websocket;
.Ve
.PP
Check if this route is a WebSocket.
.SS "methods"
.IX Subsection "methods"
.Vb 4
\& my $methods = $r\->methods;
\& $r = $r\->methods(\*(AqGET\*(Aq);
\& $r = $r\->methods(\*(AqGET\*(Aq, \*(AqPOST\*(Aq);
\& $r = $r\->methods([\*(AqGET\*(Aq, \*(AqPOST\*(Aq]);
.Ve
.PP
Restrict \s-1HTTP\s0 methods this route is allowed to handle, defaults to no restrictions.
.PP
.Vb 2
\& # Route with two methods and destination
\& $r\->any(\*(Aq/foo\*(Aq)\->methods(\*(AqGET\*(Aq, \*(AqPOST\*(Aq)\->to(\*(Aqfoo#bar\*(Aq);
.Ve
.SS "name"
.IX Subsection "name"
.Vb 2
\& my $name = $r\->name;
\& $r = $r\->name(\*(Aqfoo\*(Aq);
.Ve
.PP
The name of this route, defaults to an automatically generated name based on the route pattern. Note that the name
\&\f(CW\*(C`current\*(C'\fR is reserved for referring to the current route.
.PP
.Vb 2
\& # Route with destination and custom name
\& $r\->get(\*(Aq/user\*(Aq)\->to(\*(Aquser#show\*(Aq)\->name(\*(Aqshow_user\*(Aq);
.Ve
.SS "options"
.IX Subsection "options"
.Vb 7
\& my $route = $r\->options;
\& my $route = $r\->options(\*(Aq/:foo\*(Aq);
\& my $route = $r\->options(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->options(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->options(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->options(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->options(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
.Ve
.PP
Generate Mojolicious::Routes::Route object matching only \f(CW\*(C`OPTIONS\*(C'\fR requests, takes the same arguments as \*(L"any\*(R"
(except for the \s-1HTTP\s0 methods to match, which are implied). See Mojolicious::Guides::Tutorial and
Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Route with destination
\& $r\->options(\*(Aq/user\*(Aq)\->to(\*(Aquser#overview\*(Aq);
.Ve
.SS "parse"
.IX Subsection "parse"
.Vb 3
\& $r = $r\->parse(\*(Aq/user/:id\*(Aq);
\& $r = $r\->parse(\*(Aq/user/:id\*(Aq, id => qr/\ed+/);
\& $r = $r\->parse(format => [\*(Aqjson\*(Aq, \*(Aqyaml\*(Aq]);
.Ve
.PP
Parse pattern.
.SS "patch"
.IX Subsection "patch"
.Vb 7
\& my $route = $r\->patch;
\& my $route = $r\->patch(\*(Aq/:foo\*(Aq);
\& my $route = $r\->patch(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->patch(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->patch(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->patch(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->patch(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
.Ve
.PP
Generate Mojolicious::Routes::Route object matching only \f(CW\*(C`PATCH\*(C'\fR requests, takes the same arguments as \*(L"any\*(R"
(except for the \s-1HTTP\s0 methods to match, which are implied). See Mojolicious::Guides::Tutorial and
Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Route with destination
\& $r\->patch(\*(Aq/user\*(Aq)\->to(\*(Aquser#update\*(Aq);
.Ve
.SS "post"
.IX Subsection "post"
.Vb 7
\& my $route = $r\->post;
\& my $route = $r\->post(\*(Aq/:foo\*(Aq);
\& my $route = $r\->post(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->post(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->post(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->post(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->post(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
.Ve
.PP
Generate Mojolicious::Routes::Route object matching only \f(CW\*(C`POST\*(C'\fR requests, takes the same arguments as \*(L"any\*(R"
(except for the \s-1HTTP\s0 methods to match, which are implied). See Mojolicious::Guides::Tutorial and
Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Route with destination
\& $r\->post(\*(Aq/user\*(Aq)\->to(\*(Aquser#create\*(Aq);
.Ve
.SS "put"
.IX Subsection "put"
.Vb 7
\& my $route = $r\->put;
\& my $route = $r\->put(\*(Aq/:foo\*(Aq);
\& my $route = $r\->put(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->put(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->put(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->put(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->put(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
.Ve
.PP
Generate Mojolicious::Routes::Route object matching only \f(CW\*(C`PUT\*(C'\fR requests, takes the same arguments as \*(L"any\*(R"
(except for the \s-1HTTP\s0 methods to match, which are implied). See Mojolicious::Guides::Tutorial and
Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Route with destination
\& $r\->put(\*(Aq/user\*(Aq)\->to(\*(Aquser#replace\*(Aq);
.Ve
.SS "remove"
.IX Subsection "remove"
.Vb 1
\& $r = $r\->remove;
.Ve
.PP
Remove route from parent.
.PP
.Vb 2
\& # Remove route completely
\& $r\->find(\*(Aqfoo\*(Aq)\->remove;
\&
\& # Reattach route to new parent
\& $r\->any(\*(Aq/foo\*(Aq)\->add_child($r\->find(\*(Aqbar\*(Aq)\->remove);
.Ve
.SS "render"
.IX Subsection "render"
.Vb 1
\& my $path = $r\->render({foo => \*(Aqbar\*(Aq});
.Ve
.PP
Render route with parameters into a path.
.SS "root"
.IX Subsection "root"
.Vb 1
\& my $root = $r\->root;
.Ve
.PP
The Mojolicious::Routes object this route is a descendant of.
.SS "requires"
.IX Subsection "requires"
.Vb 4
\& my $requires = $r\->requires;
\& $r = $r\->requires(foo => 1);
\& $r = $r\->requires(foo => 1, bar => {baz => \*(Aqyada\*(Aq});
\& $r = $r\->requires([foo => 1, bar => {baz => \*(Aqyada\*(Aq}]);
.Ve
.PP
Activate conditions for this route. Note that this automatically disables the routing cache, since conditions are too
complex for caching.
.PP
.Vb 2
\& # Route with condition and destination
\& $r\->get(\*(Aq/foo\*(Aq)\->requires(host => qr/mojolicious\e.org/)\->to(\*(Aqfoo#bar\*(Aq);
.Ve
.SS "suggested_method"
.IX Subsection "suggested_method"
.Vb 1
\& my $method = $r\->suggested_method;
.Ve
.PP
Suggested \s-1HTTP\s0 method for reaching this route, \f(CW\*(C`GET\*(C'\fR and \f(CW\*(C`POST\*(C'\fR are preferred.
.SS "to"
.IX Subsection "to"
.Vb 12
\& my $defaults = $r\->to;
\& $r = $r\->to(action => \*(Aqfoo\*(Aq);
\& $r = $r\->to({action => \*(Aqfoo\*(Aq});
\& $r = $r\->to(\*(Aqcontroller#action\*(Aq);
\& $r = $r\->to(\*(Aqcontroller#action\*(Aq, foo => \*(Aqbar\*(Aq);
\& $r = $r\->to(\*(Aqcontroller#action\*(Aq, {foo => \*(Aqbar\*(Aq});
\& $r = $r\->to(Mojolicious\->new);
\& $r = $r\->to(Mojolicious\->new, foo => \*(Aqbar\*(Aq);
\& $r = $r\->to(Mojolicious\->new, {foo => \*(Aqbar\*(Aq});
\& $r = $r\->to(\*(AqMyApp\*(Aq);
\& $r = $r\->to(\*(AqMyApp\*(Aq, foo => \*(Aqbar\*(Aq);
\& $r = $r\->to(\*(AqMyApp\*(Aq, {foo => \*(Aqbar\*(Aq});
.Ve
.PP
Set default parameters for this route.
.SS "to_string"
.IX Subsection "to_string"
.Vb 1
\& my $str = $r\->to_string;
.Ve
.PP
Stringify the whole route.
.SS "under"
.IX Subsection "under"
.Vb 6
\& my $route = $r\->under(sub ($c) {...});
\& my $route = $r\->under(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->under(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq});
\& my $route = $r\->under(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/]);
\& my $route = $r\->under(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/));
\& my $route = $r\->under([format => [\*(Aqjson\*(Aq, \*(Aqyaml\*(Aq]]);
.Ve
.PP
Generate Mojolicious::Routes::Route object for a nested route with its own intermediate destination, takes the same
arguments as \*(L"any\*(R" (except for the \s-1HTTP\s0 methods to match, which are not available). See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Longer version
\& $r\->any(\*(Aq/:foo\*(Aq => sub ($c) {...})\->inline(1);
\&
\& # Intermediate destination and prefix shared between two routes
\& my $auth = $r\->under(\*(Aq/user\*(Aq)\->to(\*(Aquser#auth\*(Aq);
\& $auth\->get(\*(Aq/show\*(Aq)\->to(\*(Aq#show\*(Aq);
\& $auth\->post(\*(Aq/create\*(Aq)\->to(\*(Aq#create\*(Aq);
.Ve
.SS "websocket"
.IX Subsection "websocket"
.Vb 7
\& my $route = $r\->websocket;
\& my $route = $r\->websocket(\*(Aq/:foo\*(Aq);
\& my $route = $r\->websocket(\*(Aq/:foo\*(Aq => sub ($c) {...});
\& my $route = $r\->websocket(\*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq);
\& my $route = $r\->websocket(\*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...});
\& my $route = $r\->websocket(\*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...});
\& my $route = $r\->websocket(\*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...});
.Ve
.PP
Generate Mojolicious::Routes::Route object matching only WebSocket handshakes, takes the same arguments as \*(L"any\*(R"
(except for the \s-1HTTP\s0 methods to match, which are implied). See Mojolicious::Guides::Tutorial and
Mojolicious::Guides::Routing for more information.
.PP
.Vb 2
\& # Route with destination
\& $r\->websocket(\*(Aq/echo\*(Aq)\->to(\*(Aqexample#echo\*(Aq);
.Ve
.SH "SHORTCUTS"
.IX Header "SHORTCUTS"
In addition to the \*(L"\s-1ATTRIBUTES\*(R"\s0 and \*(L"\s-1METHODS\*(R"\s0 above you can also call shortcuts provided by \*(L"root\*(R" on
Mojolicious::Routes::Route objects.
.PP
.Vb 4
\& # Add a "firefox" shortcut
\& $r\->root\->add_shortcut(firefox => sub ($r, $path) {
\& $r\->get($path, agent => qr/Firefox/);
\& });
\&
\& # Use "firefox" shortcut to generate routes
\& $r\->firefox(\*(Aq/welcome\*(Aq)\->to(\*(Aqfirefox#welcome\*(Aq);
\& $r\->firefox(\*(Aq/bye\*(Aq)\->to(\*(Aqfirefox#bye\*(Aq);
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.