I'm using Magento 2 CE Version 2.1.0
Taking reference of http://inchoo.net/magento-2/routing-in-magento-2/ for Routing.
My Router.php
Controller Code
public function match(\Magento\Framework\App\RequestInterface $request) {
$identifier = trim($request->getPathInfo(), '/');
if (strpos($identifier, 'test') !== false) {
$request->setModuleName('moduletest')->setControllerName('test')->setActionName('test');
} else {
//There is no match
return;
}
return $this->actionFactory->create(
'Magento\Framework\App\Action\Forward', ['request' => $request]
);
}
I found @ vendor\magento\framework\App\FrontController.php
public function dispatch(RequestInterface $request)
{
\Magento\Framework\Profiler::start('routers_match');
$routingCycleCounter = 0;
$result = null;
while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
/** @var \Magento\Framework\App\RouterInterface $router */
foreach ($this->_routerList as $router) {
try {
$actionInstance = $router->match($request);
if ($actionInstance) {
$request->setDispatched(true);
$this->response->setNoCacheHeaders();
if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) {
$result = $actionInstance->dispatch($request);
} else {
$result = $actionInstance->execute();
}
break;
}
} catch (\Magento\Framework\Exception\NotFoundException $e) {
$request->initForward();
$request->setActionName('noroute');
$request->setDispatched(false);
break;
}
}
}
\Magento\Framework\Profiler::stop('routers_match');
if ($routingCycleCounter > 100) {
throw new \LogicException('Front controller reached 100 router match iterations');
}
return $result;
}
I have downloaded http://inchoo.net/magento-2/routing-in-magento-2/ gitHub code & installed & working fine. But it's not working for my custom module.
When i type http://localhost/magento2/mymodule/examplerouter it goes to InChoo Controller router not mine.
How to solve this issue?