I try to override a router, and I encounter some difficulties.
I try an override in the following way:
In my module2 DI : namespace2/module2/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="{Namespace1}\{module1}\Controller\Router" type="{Namespace2}\{module2}\Controller\Router" />
</config>
In my module2 frontend routes : namespace2/module2/etc/frontend/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="{namespace2}">
<module name="{namespace2}_{module2}" before="{namespace1}_{module1}" />
</route>
</router>
</config>
In my module2 router : namespace2/module2/Controller/Router
<?php
namespace Namespace2\Module2\Controller;
use Magento\Framework\App\RequestInterface;
class Router extends \Namespace1\Module1\Controller\Router
{
public function __construct()
{
die('ok');
}
}
But after DI compile, my override not works.
Can you help me ? Thanks