Nov 09, 2020 in Drupal 8

I like drupal console a lot as a helper tool for development. In this snippet I wanted to get the route route of a views page. The page is on /news-events. 

drupal router:debug | grep '/news-events'

This returned:

 view.news.page_1    /news-events

Now I can use this uri to set a redirection in my EventSubscriber:

    $redirect_url = Url::fromRoute('view.news.page_1');
    $response = new RedirectResponse($redirect_url->toString(), 301);
    $event->setResponse($response);

 

Comments