Dynamic Routes in Drupal 8 with a RouteSubscriber
Previously I have demonstrated how to create a new route controller in Using Drupal 8's new route controllers then how to restrict access to it in Controlling Access to Drupal 8 Routes with Access Checks. But that's not where the fun ends!
What about when we need to create a route dynamically. For example, if we need to create routes for content types that we don't know will exist in advance? In Drupal 7, we created dynamic routes with a foreach loop in hook_menu(). In Drupal 8, we can do all this and more with a RouteSubscriber.