Redirect examples - Drupal 8
Ex:
use Symfony\Component\HttpFoundation\RedirectResponse;
// Redirect to specific route or URL.
return new RedirectResponse(\Drupal::url('user.page'));
return new RedirectResponse(\Drupal::url('locale.translate_status', [], ['absolute' => TRUE]));
return new RedirectResponse(\Drupal::url('<front>', [], ['absolute' => TRUE]));
return new RedirectResponse(Url::fromRoute('system.modules_uninstall')->setAbsolute()->toString());
return new RedirectResponse(Url::fromRoute('<current>')->toString());
// Redirect to external URL.
use Drupal\Core\Routing\TrustedRedirectResponse;
return new TrustedRedirectResponse('http://www.google.com/');
// If you have extended ControllerBase class or use Drupal\Core\Routing\UrlGeneratorTrait;
return $this->redirect('user.login');
// If you have configurable URL
return new RedirectResponse(URL::fromUserInput('/user-input-url')->toString());
Comments
Post a Comment