Cannot find route error

Created on 8 June 2017, over 7 years ago
Updated 23 February 2023, over 1 year ago

Just followed the steps listed on the module page, and am getting this:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "search.view_node_search" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 190 of core/lib/Drupal/Core/Routing/RouteProvider.php).

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada rferguson

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    Same issue here! Any plans to finally fix this?

  • 🇩🇪Germany Anybody Porta Westfalica

    Okay, let's bring some light into this issue!

    search.view_node_search route is the default route created for the "Content" search from Drupal core installation.
    search.view is the route of the general search page, while
    search.view_{MACHINE_NAME} is the route of the search page type.

    So you have to enter "node_search" as machine name of your new search page to replace the core node search!

    The logic can be found in the Core search module in the core/modules/search/src/Routing/SearchPageRoutes.php:

    
    /**
       * Returns an array of route objects.
       *
       * @return \Symfony\Component\Routing\Route[]
       *   An array of route objects.
       */
      public function routes() {
        $routes = [];
        // @todo Decide if /search should continue to redirect to /search/$default,
        //   or just perform the appropriate search.
        if ($default_page = $this->searchPageRepository->getDefaultSearchPage()) {
          $routes['search.view'] = new Route(
            '/search',
            [
              '_controller' => 'Drupal\search\Controller\SearchController::redirectSearchPage',
              '_title' => 'Search',
              'entity' => $default_page,
            ],
            [
              '_entity_access' => 'entity.view',
              '_permission' => 'search content',
            ],
            [
              'parameters' => [
                'entity' => [
                  'type' => 'entity:search_page',
                ],
              ],
            ]
          );
        }
        $active_pages = $this->searchPageRepository->getActiveSearchPages();
        foreach ($active_pages as $entity_id => $entity) {
          $routes["search.view_$entity_id"] = new Route(
            '/search/' . $entity->getPath(),
            [
              '_controller' => 'Drupal\search\Controller\SearchController::view',
              '_title' => 'Search',
              'entity' => $entity_id,
            ],
            [
              '_entity_access' => 'entity.view',
              '_permission' => 'search content',
            ],
            [
              'parameters' => [
                'entity' => [
                  'type' => 'entity:search_page',
                ],
              ],
            ]
          );
    [...]
    

    Some themes simply seem to rely on {{ path('search.view_node_search') }} being present, so this module should at least document this edge case and how to solve it.

    After uninstalling the module, you have to re-import the core node_search search or add it manually with exactly that module name!

    Hooray!

Production build 0.71.5 2024