Skip to main content

Posts

Showing posts from August, 2022

How to create custom router in Magento 2?

In this blog, we will discuss Magento routing and how to create a custom router for any existing router. The route defines the name of the module which is responsible for the requested URL.  The FrontController class searches through a list of routers, provided by the RouterList class until it matches one that can process a request. When the FrontController finds a matching router, it dispatches the request to an action class returned by the router. Standard Router For example, if URL http://localhost/demo/request/path is called from the browser then it defines  demo as the module_name/front_name, request as the controller_name & path as the action_name.  When we create a new module, routes are defined in the  routes.xml file maps which module to use for a URL with a specific frontName and area. The location of the routes.xml file in a module, either etc/frontend or etc/adminhtml , specifies where those routes are active. <config xmlns:xsi="http://www.w3.org/20