How to redirect to edit page on node create? I am trying this code in my custom module but it does not redirect to the node edit page.

 function mymodule_entity_insert(EntityInterface $entity) {
   if ($entity instanceof \Drupal\node\NodeInterface){
        $id=$entity-&gt;id();
        return new RedirectResponse("/node/$id/edit");
      }
   }
When not in a Controller call the send() method on the RedirectResponse object.

$response = new RedirectResponse("/node/$id/edit");
$response-&gt;send();