Drupal8 Redirection

22 Apr 2020

Redirect Method in DRUPAL8

Published On: Wed, 04/22/2020 - 22:13

Method to redirect on node id url

$url = Url::fromRoute('entity.node.canonical', ['node' => $nid]);

Method to redirect on custom url

$url = Url::fromRoute('olsys.mycustom_dashboard');

Redirect on user view page of loggedin user

use Drupal\Core\Controller\ControllerBase; // Use this on top
return $this->redirect('user.page');	// use this as your code 

$url = \Drupal\…