How do I programmatically fix local menus to be shown only for a content type? I am using the following lines in a links.task.yml file.
x.nodename_updates:
  route_name: view.great_view_name1.page_1
  base_route: entity.node.canonical
  title: 'Updates'
  weight: 50

x.nodename_subscriptions:
  route_name: view.great_view_name2.page_1
  base_route: entity.node.canonical
  title: 'Subscriptions'
  weight: 50

The submenus are shown on all nodes. I would like to show them for a single content type, but when I use the entity name in the base_route such as entity.TYPE.canonical, it doesn't work. It works for other entities that are defined in classes with annotations.
I know it is possible to fix it through hook_menu_local_task_alter(), but this is something I believe can be fixed within the links.task.yml file.
I don't konw if there's a better way to do it now but few years ago I did it using a custom access: https://stackoverflow.com/questions/36496998/drupal-8-how-to-add-task-and-contextual-links-for-specific-node-type/36636263#36636263
In my case it was easier because I was creating the routes in my module.
Since your routes are created by views you would need to implement a RouteSubscriber to alter the route, add the _custom_access and _node_types requirements.
/!\ Warning: I am not sure since I never tried it on views routes but it might conflicts or breaks the rules you've set from the views UI to access this view. It should be compatible with a _permission rule, maybe not with an _entity_access rule.
yourmodule/yourmodule.services.yml
services:
  yourmodule.route_subscriber:
    class: Drupal\yourmodule\Routing\RouteSubscriber
    tags:
    - { name: event_subscriber }

yourmodule/src/Routing/RouteSubscriber.php
&lt;?php

namespace Drupal\yourmodule\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  public function alterRoutes(RouteCollection $collection) {
    if ($route = $collection-&gt;get('view.great_view_name1.page_1')) {
      $requirements = $route-&gt;getRequirements();
      $requirements['_custom_access'] = '\Drupal\yourmodule\Access\ByNodeTypeAccessCheck::access';
      // Replace 'my_node_type' with the name of the node type you want.
      // Since it's an array, you can add more than one node type.
      $requirements['_node_types'] = ['my_node_type'];
      $requirements['node'] = '\d+';
      $route-&gt;setRequirements($requirements);
      
      $options = $route-&gt;getOptions();
      $options['parameters'] = $options['parameters'] ?? [];
      $options['parameters']['node'] = [
        'type' =&gt; [
          'entity:node',
        ],
      ];
      $route-&gt;setOptions($options);
    }
  }

}

yourmdule/src/Access/ByNodeTypeAccessCheck.php
namespace Drupal\yourmdule\Access;

use Drupal\Core\Access\AccessCheckInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\node\NodeInterface;
use Symfony\Component\Routing\Route;

/**
 * Check the access to a node task based on the node type.
 */
class ByNodeTypeAccessCheck implements AccessCheckInterface {

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return NULL;
  }

  /**
   * A custom access check.
   *
   * @param \Drupal\node\NodeInterface $node
   *   Run access checks for this node.
   */
  public function access(Route $route, NodeInterface $node) {
    if ($route-&gt;hasRequirement('_node_types')) {
      $allowed_node_types = $route-&gt;getRequirement('_node_types');
      if (in_array($node-&gt;getType(), $allowed_node_types)) {
        return AccessResult::allowed();
      }
    }
    return AccessResult::forbidden();
  }

}