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:
- 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
- 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)...