To get the current route based on the URL (more reliable in case of forwards):
public function getCurrentRoute(Request $request)
{
$pathInfo = $request->getPathInfo();
$routeParams = $this->router->match($pathInfo);
$routeName = $routeParams['_route'];
if (substr($routeName, 0, 1) === '_') {
return;
}
unset($routeParams['_route']);
$data = [
'name' => $routeName,
'params' => $routeParams,
];
return $data;
}