How do I verify a route exists? In Drupal 8, I need to verify a route exists or not in a custom module. How can I achieve this?
/* @var \Drupal\Core\Routing\RouteProviderInterface $route_provider */
$route_provider = \Drupal::service('router.route_provider');
$route_provider-&gt;getRouteByName('abc.xyz');


RouteProviderInterface::getRouteByName() returns a \Symfony\Component\Routing\Route object if it exists, or throws an exception if it does not.

You can use RouteProviderInterface::getRoutesByNames() if you don't want an exception.

$exists = count($route_provider-&gt;getRoutesByNames(['abc.xyz'])) === 1;