RedirectResponse not able to redirect in hook_entity_view drupal 8 I am trying to redirect users to a page on entity view. I am using RedirectResponse in hook_entity_view. But it is not redirecting to the desired page.

This is how I implemented this.
After fetching my redirect url, I have passed it to RedirectResponse.

return new RedirectResponse($redirect_url);

Thank you
Thank you, I got it working.
Don't need to return the object of RedirectResponse. It works like this.

$response = new RedirectResponse($redirect_url);

$response->send();

It works this way.