title: Replace Symfony 5 default router
body: <p>Using the CMF code as a reference I am trying to replace the default router with the chain router...not just decorate...</p>
  
  <pre><code>public function process(ContainerBuilder $container)
  {
      // NOT available using alias for some reason???
      $definition = $container-&gt;getDefinition('MyBundle\Routing\ChainRouter');
  
      foreach ($container-&gt;findTaggedServiceIds($this-&gt;routerTag) as $id =&gt; $attributes) {
          $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
          $definition-&gt;addMethodCall('add', [new Reference($id), $priority]);
      }
  
      $container-&gt;setDefinition('router.default', $definition);
  }
  </code></pre>
  
  <p>Here is the bundle services.xml</p>
  
  <pre><code> &lt;services&gt;
  
          &lt;service id="MyBundle\Routing\ChainRouter" /&gt;
          &lt;service id="cmf_routing.router" alias="MyBundle\Routing\ChainRouter" /&gt;
  
  &lt;!--        &lt;service id="MyBundle\Routing\DynamicRouter"&gt;--&gt;
  &lt;!--            &lt;tag name="router" priority="100" /&gt;--&gt;
  &lt;!--        &lt;/service&gt;--&gt;
  
          &lt;service id="Symfony\Bundle\FrameworkBundle\Routing\Router"&gt;
              &lt;tag name="router" priority="1" /&gt;
  
              &lt;tag name="monolog.logger" channel="router" /&gt;
              &lt;tag name="container.service_subscriber" id="routing.loader" /&gt;
              &lt;argument type="service" id="Psr\Container\ContainerInterface" /&gt;
              &lt;argument&gt;%router.resource%&lt;/argument&gt;
              &lt;argument type="collection"&gt;
                  &lt;argument key="cache_dir"&gt;%kernel.cache_dir%&lt;/argument&gt;
                  &lt;argument key="debug"&gt;%kernel.debug%&lt;/argument&gt;
                  &lt;argument key="generator_class"&gt;Symfony\Component\Routing\Generator\CompiledUrlGenerator&lt;/argument&gt;
                  &lt;argument key="generator_dumper_class"&gt;Symfony\Component\Routing\Generator\Dumper\CompiledUrlGeneratorDumper&lt;/argument&gt;
                  &lt;argument key="matcher_class"&gt;Symfony\Bundle\FrameworkBundle\Routing\RedirectableCompiledUrlMatcher&lt;/argument&gt;
                  &lt;argument key="matcher_dumper_class"&gt;Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper&lt;/argument&gt;
              &lt;/argument&gt;
              &lt;argument type="service" id="router.request_context" on-invalid="ignore" /&gt;
              &lt;argument type="service" id="parameter_bag" on-invalid="ignore" /&gt;
              &lt;argument type="service" id="logger" on-invalid="ignore" /&gt;
              &lt;argument&gt;%kernel.default_locale%&lt;/argument&gt;
              &lt;call method="setConfigCacheFactory"&gt;
                  &lt;argument type="service" id="config_cache_factory" /&gt;
              &lt;/call&gt;
          &lt;/service&gt;
  </code></pre>
  
  <p>I am getting an error <strong>Cannot load resource "kernel::loadRoutes"</strong></p>
  
  <p>With the following stack trace</p>
  
  <pre><code>LoaderLoadException Symfony\Component\Config\Exception\LoaderLoadException: Cannot load resource "kernel::loadRoutes".
  
    at vendor/symfony/config/Loader/DelegatingLoader.php:37   at Symfony\Component\Config\Loader\DelegatingLoader-&gt;load('kernel::loadRoutes', null)
       (vendor/symfony/framework-bundle/Routing/DelegatingLoader.php:67)   at Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader-&gt;load('kernel::loadRoutes', null)
       (vendor/symfony/framework-bundle/Routing/Router.php:66)   at Symfony\Bundle\FrameworkBundle\Routing\Router-&gt;getRouteCollection()
       (vendor/symfony/routing/Router.php:358)   at Symfony\Component\Routing\Router-&gt;getMatcherDumperInstance()
       (vendor/symfony/routing/Router.php:289)   at Symfony\Component\Routing\Router-&gt;Symfony\Component\Routing\{closure}(object(ResourceCheckerConfigCache))
       (vendor/symfony/config/ResourceCheckerConfigCacheFactory.php:39)   at Symfony\Component\Config\ResourceCheckerConfigCacheFactory-&gt;cache('/vagrant/project/var/cache/dev/url_matching_routes.php', object(Closure))
       (vendor/symfony/routing/Router.php:297)   at Symfony\Component\Routing\Router-&gt;getMatcher()
       (vendor/symfony/routing/Router.php:251)   at Symfony\Component\Routing\Router-&gt;matchRequest(object(Request))
       (/vagrant/bundles/mybundle/src/Routing/ChainRouter.php:191)   at MyBundle\Routing\ChainRouter-&gt;doMatch('/', object(Request))
       (/vagrant/bundles/mybundle/src/Routing/ChainRouter.php:158)   at MyBundle\Routing\ChainRouter-&gt;matchRequest(object(Request))
       (vendor/symfony/http-kernel/EventListener/RouterListener.php:112)
  </code></pre>
  
  <p>truncated for brevity...</p>
  
  <p>I feel this is being caused by the default router being "replaced" in the compiler pass and not properly re-initialized. Seeing as the DynamicRouter isn't even loaded the expected behavior was business as usual, not this error :) </p>
  
  <p>Any thoughts, pointers, tips, suggestions?</p>