How to get the Route object from an URI?
You can retrieve this information from the Symfony router. This can be accessed in Drupal through the router.no_access_checks service.

If you have a simple path (note that the path has a leading slash):

$router = \Drupal::service('router.no_access_checks');
$result = $router-&gt;match('/node/2');


If you have a Url object:

$router = \Drupal::service('router.no_access_checks');
$result = $router-&gt;match($url-&gt;toString());


This will return an array that includes the route object, as well as other useful information such as the route name and route parameters, the controller, the title callback and even the entity object represented by the URL.