Alter existing route to a different route for a specific content type node using RouteSubscriber I want to modify node edit of a specific content type node to a different route .

Eg : suppose i have a node edit page route as entity.node.edit_form (core feature) . And now i want to change this route to custom_module.edit_form when taking the node to edit . 

I refered This  which explains altering the existing route to a different route . It only says to route to a different url . It may not work in my case as node edit form will contain node id as parameter . Its not mentioning how routes can be placed in $route-&gt;setPath() though . 

For eg:
In custom_module/src/Routing/RouteSubscriber.php

/**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    // Change path '/user/login' to '/login'.
    if ($route = $collection-&gt;get('user.login')) {
      $route-&gt;setPath('/login');
    }
    // Always deny access to '/user/logout'.
    // Note that the second parameter of setRequirement() is a string.
    if ($route = $collection-&gt;get('user.logout')) {
      $route-&gt;setRequirement('_access', 'FALSE');
    }
  }


How can i do this ?
You need to change the _controller for the route, check this code:

&lt;?php

namespace Drupal\drush_help\Routing;

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

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

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    // Change the controller for the help page.
    if ($route = $collection-&gt;get('help.page')) {
      $route-&gt;setDefault('_controller', '\Drupal\drush_help\Controller\HelpController::helpPage');
    }
  }

}


In this case the route is altered to replace the Drupal help page for a custom controller.

If you want to see this in action go to check the code of the Drush Help module.

Disclosure: I'm the maintainer of the module Drush Help.