I'm using Magento 2 CE Version 2.1.0.
app\code\Custom\Module\etc\frontend\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Framework\App\RouterList">
<arguments>
<argument name="routerList" xsi:type="array">
<item name="custom_module" xsi:type="array">
<item name="class" xsi:type="string">Custom\Module\Controller\Router</item>
<item name="disable" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">22</item>
</item>
</argument>
</arguments>
</type>
<virtualType name="CustomModuleRoutingEntityPosts" type="custom\module\Model\Routing\Entity">
<arguments>
<argument name="prefixConfigPath" xsi:type="const">Custom\Module\Model\Posts\Url::URL_PREFIX_CONFIG_PATH</argument>
<argument name="suffixConfigPath" xsi:type="const">Custom\Module\Model\Posts\Url::URL_SUFFIX_CONFIG_PATH</argument>
<argument name="factory" xsi:type="object">Custom\Module\Model\PostsFactory</argument>
<argument name="controller" xsi:type="string">posts</argument>
</arguments>
</virtualType>
<type name="Custom\Module\Controller\Router">
<arguments>
<argument name="routingEntities" xsi:type="array">
<item name="posts" xsi:type="object">CustomModuleRoutingEntityPosts</item>
</argument>
</arguments>
</type>
</config>
For Defining Scope there will be <argument name="defaultScope" xsi:type="string">posts</argument> Global, Frontend, Primary i have seen.
I would like to put condition in di.xml if there is particular URL http://localhost/magento2/mymodule/test.html then only it will call this di.xml file otherwise not.
I have created custom Router.php, when i call Magento 2 Default Category/Product List then also it goes to my custom Router.php, So what's the best way so it's limited to my Custom Module Only.
I'm following https://github.com/tzyganu/Magento2SampleModule/blob/master/Controller/Router.php
When i do
public function match(\Magento\Framework\App\RequestInterface $request) {
echo 1;exit;
}
Each & every Request call this custom router. Which i think not correct. So that's why it needed to define Scope for Router.php via di.xml or Any other Magento Standard way.
Thanks