In my custom submit handler I want to redirect to a view page Url, let's suppose my view name is team and its path is /admin/team, I find out I should use $from_state->setRedirect('route'); but when I tried $from_state->setRedirect('/admin/team'); Faced with error, How can I get view route name in?

  • This is also required for static YAML menu configuration. – vijaycs85 Sep 27 '17 at 9:54

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');

and for your case

$url = Url::fromRoute('view.team.page_1'); // page_1 is my guess as to your page name, please replace it with your page machine_name

Lean more : How to formulate the route name

after @4k4 comment, Also you can redirect form to custom router with URL

just need use $form_state->setRedirectUrl($url)


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

$url = Url::fromRoute('view.team.page_1', ['arg_0' => 1234]);

The Webprofiler of the devel module let's you see the route of any page.

It also displays the number of DB queries made on the page and also the request time in addition to many other features.

It's available for Drupal 7 and 8.


Simple example: It will work :)

use Drupal\Core\Url;
$form_state->setRedirect('view.VIEW_MACHINE_NAME.PAGE_MACHINENAME'); // view.my_view.page_1

For Durpal 8 you might look into the "router" database table aswell to get your redirct parameters.

Look for the corresponding value in the "name" column and compare against the path column.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.