Form state redirect to node path plus fragment How can I redirect a form to the canonical node path + fragment?

Redirect: /nodepathalias#tag

$form_state-&gt;setRedirect('entity.node.canonical',
  array('node' =&gt; $node-&gt;id()),
));


Where should I add the fragment information?
Use the third argument of the setRedirect function:


  array $options: (optional) An associative array of additional options.
  See \Drupal\Core\Url for the available keys.


And if you check that doc:


  @param array $options   (optional) An associative array of additional
  URL options, with the   following elements:
  
  
  'query': An array of query key/value-pairs (without any URL-encoding)
  to append to the URL.
  'fragment': A fragment identifier (named anchor) to append to the URL.
  Do not include the leading '#' character.
  'absolute': Defaults to FALSE. Whether to force the output to be an
  absolute link (beginning with http:). Useful for links that will be
  displayed outside the site, such as in an RSS feed.
  'attributes': An associative array of HTML attributes that will be
  added to the anchor tag if you use the \Drupal\Core\Link class to make
  the link.
  'language': An optional language object used to look up the alias
  for the URL. If $options['language'] is omitted, it defaults to the
  current language for the language type LanguageInterface::TYPE_URL.
  'https': Whether this URL should point to a secure location. If not
  defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
  


In your case you should use just fragment:

$options = [
  'fragment'   =&gt; 'tag',
];

$form_state-&gt;setRedirect('entity.node.canonical',
  ['node' =&gt; 8],
  $options
);