Read More
Read More
Menu Close

    Custom router in Magento2

    In this post, you will learn how to create a custom router in magento2.

    To Create the Router first, need to add our custom route into the \Magento\Framework\App\RouterList class.

    For this, we use the di.xml file in our module.

    Check the Following path: app/code/Vendor/Module/etc/frontend/di.xml

    After that, now we need to create a custom router class.

    Searching for an experienced
    Magento 2 Company ?
    Read More

    It will match the custom route name learning with the existing routing route.

    Check the Following path: app/code/Vendor/Module/Controller/Router.php:

    Now, we need to create our routes.xml file under:

    app/code/Vendor/Module/etc/frontend/routes.xml

    Let’s check the above route as an example, Declaring the layout handler for our new route:

    Vendor/Module/view/frontend/layout/routing_index_index.xml

    Creating the controller that will handle the routing route and will get the parameters passed by our router.

    Vendor/Module/Controller/Index/Index.php

    As a result, accessing the http://site.com/learning route, the http://site.com/routing/index/index route is loaded.

    Screenshot-from-2022-05-06-13-11-36

    That’s it.

    Happy Coding !!

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top