Drupal 8 Page Not Found (Custom Module Page Life Cycle)
If you have developed in Drupal 8 and have created custom Modules, you might have seen an error that says "Page Not Found" when you try to navigate to the URL defined in the routing file of your custom module. This error can be a pain to debug, the reason why it could be a pain to debug especially in Drupal 8 is that Drupal uses PHP Scripting/Programming which can be hard to step through.
Furthermore, debugging in PHP is somehow tricky when your background has been developing in C# which is compiled and interpreted in Machine Language and very much easy to debug.
Long short, the reason why the error might be omitted is that the routing is absolutely wrong. This could be many reasons but, I believe you would have enabled errors so to be clear what errors are there. When you find yourself hard to comprehend the error or what is going on, try to apply common sense to Drupal Page Life Cycle;
First: when you call a page e.g, type a URL to the page, Drupal scans the routing files and finds where the routing has a name of the typed URL, now hear me out, I don't know whether Drupal Scans or Seeks the Core Files System but whatever the Retrieval algorithm is, it somehow searches and finds where the name of URL is defined in the routing files of custom modules or even the database for specifics.
Second: You have to make sure the routing is defined accordingly, this includes the naming of the Head Router in YAML format
, the heading of every router in a custom page module should be different. I did not have anyone tell me this but found out in a hard way. Watch out, and make sure the routing header is unique to the module. Watch this video to understand better.