- Issue created by @grenuy
When accessing pages with unrouted URIs while using Gin Toolbar module, users encounter an error: "UnexpectedValueException: Unrouted URIs do not have internal representations." This breaks the admin interface and prevents proper usage of the site when accessing certain paths. The issue specifically occurs in the getNavigationActiveTrail() method when it tries to get the internal path of a URL without a proper Drupal route.
Install and enable Gin theme and Gin Toolbar module
Access a URL that doesn't have a defined route in Drupal (such as a custom 404 page or certain language-specific paths)
Observe the following error in logs or on screen:
UnexpectedValueException: Unrouted URIs do not have internal representations. in Drupal\Core\Url->getInternalPath() (line 785 of core/lib/Drupal/Core/Url.php).
Drupal\gin\GinNavigation->getNavigationActiveTrail() (Line: 83)
gin_toolbar_preprocess_html()
call_user_func_array() (Line: 261)
Drupal\Core\Theme\ThemeManager->render() (Line: 446)
Drupal\Core\Render\Renderer->doRender() (Line: 203)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray() (Line: 246)
Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}() (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 188)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)
The error is particularly noticeable on multilingual sites with RTL languages like Arabic.
Add a check before calling getNavigationActiveTrail() to ensure the current route exists, and wrap the call in a try-catch block to handle any exceptions that might occur, especially in multilingual contexts:
// Get active trail only if the current route actually has a name/path
// to avoid the "Unrouted URIs do not have internal representations" error
$routeName = \Drupal::routeMatch()->getRouteName();
if ($routeName !== NULL) {
try {
// Get active trail with error handling for multilingual sites
$variables['#attached']['drupalSettings']['active_trail_paths'] = $navigation->getNavigationActiveTrail();
}
catch (\Exception $e) {
// Log the error but continue execution to prevent breaking the page
\Drupal::logger('gin_toolbar')->warning('Error getting navigation active trail: @message', ['@message' => $e->getMessage()]);
// Set empty active trail to avoid JS errors
$variables['#attached']['drupalSettings']['active_trail_paths'] = [];
}
}
else {
// Set empty active trail for unrouted URIs
$variables['#attached']['drupalSettings']['active_trail_paths'] = [];
}
Commit the patch to the module
Test with multiple language configurations, particularly RTL languages like Arabic
Verify the fix works with various edge cases of unrouted URIs
None. This is a bug fix that prevents errors from breaking the admin interface.
None. The patch only adds defensive coding to prevent errors with existing API.
None.
Active
2.0
Code