In magento1 we used to have an event controller_front_init_routers
which could be used to add any route name dynamically based on some logic.
I would like to add a route name which is saved in the database (System Conifguration).
Is there any way we could do something similar in magento2 ?
Best Answer
You can implement your own router and add it to the router cycle in the di configuration.
To add your own router, you have to make the following configuration in the di.xml:
Your custom Router class has to implement Magento\Framework\App\RouterInterface
from here, its pretty much up to you to decide when your router catches requests and how they are processed.
Here is also a little devdocs entry on routing: http://devdocs.magento.com/guides/v2.0/extension-dev-guide/routing.html
Basically the routers are called in a cycle in the given sort order multiple times. The routers can modify the Request and at any time a router thinks, he can process the request, it says match = true and processes it.
The cyclecount is internally limited to (i think) a hundred cycles or sth. After that you will land on a 404 page.