Just for record purpose, posting answer:
I used alter routes() approach in which used remove function w.r.t to domain condition:
$collection->remove('route_name');
Created: module_name.services.yml (root of custom module)
module_name.route_subscriber:
class: Drupal\module_name\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
Created: RouteSubscriber.php (module_name\src\Routing)
<?php
namespace Drupal\module_name\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
class RouteSubscriber extends RouteSubscriberBase {
protected function alterRoutes(RouteCollection $collection) {
$domain = \Drupal::request()->getHost();
// check domain
if($domain == 'domain_name'){
if ($collection->get('route_name')) {
// remove route conditionally
$collection->remove('route_name');
}
}
}
}
Info: I Choose this particular approach becoz I need to enabled same module for both sites
To get more info related to routes, visit to this documentation link on official site of DRUPAL