How to use a RedirectResponse with a # (hash)? I have this code:

$event-&gt;setResponse(new RedirectResponse(base_path().'mypage#actions_clicker'));


It redirects to /mypage, but it doesn not include the #actions_clicker part. How do I make Drupal not loose the hash / # part?
Try url encoding the # fragment. so it becomes %23, e.g:

$event-&gt;setResponse(new RedirectResponse(base_path().'mypage%23actions_clicker'));


Update:

Check the browser header to see that the fragment is passed. In my local testing it was ok:

Sample code to append fragment to redirect response.

return new RedirectResponse($redirect_url . '#test', 301);




More info: https://stackoverflow.com/a/2305927/583715