How to redirect to previous page in Drupal.

PHOTO EMBED

Mon Dec 20 2021 12:17:31 GMT+0000 (Coordinated Universal Time)

Saved by @igor #drupal #php

$current_path = $this->request->getCurrentRequest()->headers->get('referer');
$path = explode('8000', $current_path);  
//8000 is just a part of a string, from where we are breaking the string.
$route_name = Url::fromUserInput($path[1])->getRouteName();
return $this->redirect($route_name, ['user' => $user->id()]);
content_copyCOPY