Set access restriction for baseroute Let's say I have the following in example.links.task.yml from a contributed module:

    example.view:
    title: 'View'
    base_route: 'entity.example.canonical'
    route_name: 'entity.example.canonical'

    example.edit_form:
    title: 'Edit'
    base_route: 'entity.example.canonical'
    route_name: 'entity.example.edit_form'

    ... more routes with the same base_route


Now I'd like to add a custom access restriction for all these local tasks. I tried to set a restriction to the base_route, thinking that all other routes with this particular base_route would have the restriction too, but it only works for entity.example.canonical. I tried the following way:

class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if (($route = $collection-&gt;get('entity.example.canonical'))) {
      $route-&gt;setRequirement('_role', 'administrator');
    }
  }

}


I could explicitly name all different routes, but I thought there might be a way to only use the base_route - not knowing if this would work though. Any ideas?
This might work

if (($route = $collection-&gt;get('entity.example.canonical'))) { // base_route
      $current_route = \Drupal::routeMatch()-&gt;getRouteObject(); // get current route
      $current_route-&gt;setRequirement('_role', 'administrator');
}