How to pass dynamic parameters through a local action button? I created a local action button with the following in my_module.links.action.yml:


my_module.content.action:
  route_name: node.add_page
  title: 'My action'
  deriver: 'Drupal\my_module\Plugin\Derivative\ContentByDomainLocalActions'
  appears_on:
    - view.affiliated_content.page_1


Then, the local action button appears in the page admin/content/domain-content/firstdomain_local

I'd like use the argument firstdomain_local from this URL path to pass it in my local action button.

So, I retrieve the param from \Drupal::routeMatch() in getDerivativeDefinitions, like in this tutorial:

class CustomLocalActions extends DeriverBase {
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this-&gt;derivatives['example.action_id'] = $base_plugin_definition;
    $this-&gt;derivatives['example.action_id']['title'] = "Add content";
    $domain = \Drupal::routeMatch()-&gt;getParameter('arg_0');
    $this-&gt;derivatives['example.action_id']['route_parameters'] = [
      'domain' =&gt; $domain
    ];
    return $this-&gt;derivatives;
  }
}


But the param of the local action button is only updated after I clear the cache. I have to clear the cache each time I use different parameter value in the URL. 

What's the correct way to pass dynamically this argument?
Local actions and local tasks are quite similar, so looking at the Customising local task behavior I've managed to pass in dynamic route parameters to my local actions by specifying the class parameter (MyClassName) in my_module.links.action.yml and overriding the LocalActionDefault::getRouteParameters() method in that class. Only one initial cache rebuild was required.

use Drupal\Core\Menu\LocalActionDefault;
use Drupal\Core\Routing\RouteMatchInterface;

class MyClassName extends LocalActionDefault {

  public function getRouteParameters(RouteMatchInterface $route_match) {
    return array(
      'my_local_action_parameter' =&gt; $route_match-&gt;getParameter('existing_parameter_from_route')
    );
  }
}