Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

Get route name of a views page in Drupal 8 & 9 using  drupal console.


In this snippet I wanted to get the route route of a views page. The page is on /news. 

drupal router:debug | grep '/news'


This returned:    /news


Now I can use this uri to set a redirection:

    $redirect_url = Url::fromRoute('');
    $response = new RedirectResponse($redirect_url->toString(), 301);


The correct routename for view is view.VIEW_MACHINE_NAME.PAGE_MACHINENAME(in another word "view.$view_id.$display_id" ) . try something like following

use \Drupal\Core\Url;

$url = Url::fromRoute('view.VIEW_MACHINE_NAME.PAGE_MACHINENAME');


To use views contextual filters as parameters use arg_X, fe.

$url = Url::fromRoute('', ['arg_0' => 12]);


Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon