Linking to a non-existent route should not throw an exception

Created on 2 June 2015, over 9 years ago
Updated 17 July 2024, 5 months ago

Problem/Motivation

If you link to a non-existent route from your code, it breaks the whole webpage on which the link is displayed. A Symfony\Component\Routing\Exception\RouteNotFoundException exception is thrown, and an "unexpected error" page is displayed to users.

This was probably done based on the expectation that it's due to broken code, but it's a pretty harsh solution considering the following scenarios:

  1. If module A links to a route provided by module B, and the two modules are usually used together (but not always), then the developer probably won't notice the problem while writing their code. But as soon as someone uses module A on a site where module B isn't installed, it will break their site. This is not a made-up scenario; it actually happened in core: #2473105: Update hook_help texts that link to modules that can be uninstalled β†’
  2. If module A links to a route provided by module B, and module B's code is updated to no longer define that route, then when a site updates module B to the newest version, module A will break.

Proposed resolution

I would expect this to behave like links in Drupal 7 and earlier do. If code tries to link to a page that doesn't exist, the link itself should render fine. When the user clicks on the link, they should get a 404.

Exactly how to achieve that is questionable though, since in the case of routes it is not clear what URL would display in the browser (the system doesn't have an actual URL to use)...

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
RoutingΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States David_Rothstein

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.

Production build 0.71.5 2024