How to get current route in the midst of a Views AJAX request I need to conditionally pass contextual filter values to a view based on the current route and am attempting to do so in hook_views_pre_view. This is the result of using AJAX via views_infinite_scroll and losing the contextual filters that I initially pass in programmatically.
On the initial request, the following works great for getting the current route in hook_views_pre_view:
$current_route_match = \Drupal::getContainer()-&gt;get('current_route_match');
$current_route_match-&gt;getRouteName();

However, when I hit the 'Load more' button supplied by views_infinite_scroll, the route name of the current route match is 'views.ajax'. While I understand that this is technically the request's route, I need to know the original route, or from where the request was made.
After digging around, I noticed that $_SERVER['HTTP_REFERER'] had the right path, but the documentation says:

Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
use Symfony\Component\HttpFoundation\Request;

if (\Drupal::routeMatch()-&gt;getRouteName() == 'views.ajax') {
    $previousUrl = \Drupal::request()-&gt;server-&gt;get('HTTP_REFERER');
    $fake_request = Request::create($previousUrl);
    $url_object = \Drupal::service('path.validator')-&gt;getUrlIfValid($fake_request-&gt;getRequestUri());
    if ($url_object) {
      $route_name = $url_object-&gt;getRouteName();
      // Do something with $route_name;
    }
  }