Note
Note: The accepted response for this question is out of date: see this change record for best practice. The accepted response for this question is out of date: See Request parameters, route name, and route object should be accessed via RouteMatch.
You should use the CurrentRouteMatchcurrent_route_match service to retrieve the current route, and then read or modify its parameters. This wraps any Symfony etc. magic.
In procedural code, you would write:use code similar to the following one.
$route = \Drupal::routeMatch()->getCurrentRouteMatch()->getRouteObject();
$title = $route->getDefault('_title');
In object-oriented code, you should implementuse dependency injection and inject the service current_route_match
(this is what \Drupal::routeMatch()
class does internally anyway.)