Passing parameter to node add form through URL node/add/termid using routing.yml drupal 8


It is used to send extra parameter in arg without using query param, Actually have overwritten the default routing by creating new route and disable the existing route.

Passing term id to node/add  form by url node/add/{termid},  if you pass like you will get page not found error, because it will consider as unknown route, according to drupal node/add and node/add/1 is different, to make it work this , created new route in custom module and called/used the default core node controllers by routing  file.

Add this in modulename.routing.yml file

 path: '/node/add/{node_type}/{termid}'
  _controller: '\Drupal\node\Controller\NodeController::add'
  _title_callback: '\Drupal\node\Controller\NodeController::addPageTitle'
  _node_add_access: 'node:{node_type}'
  _node_operation_route: TRUE
    with_config_overrides: TRUE
 path: '/node/add/yourcontentypewhenaccessingwithouttermid'
  _access: 'FALSE'