Magento – How to define multiple routes in single module

magento2module

I am defining two routes to be used in same module.

<router id="standard">    
    <route frontName="hello" id="hello">
        <module name="HelloWorld_Hello"/>
    </route>
    <route frontName="blog" id="blog">
        <module name="HelloWorld_Hello"/>
    </route>
</router>

This is not working as expected.

I am expecting it to work like

websitename/hello
websitename/blog

I created Controller folder inside that created Blog and Index folder with Blog.php and Index.php with execute method.

Could you please tell me where is the problem?

Thanks

Best Answer

let me explain to you how it work. these two frontName will go to same controller Controller/Index/Index.php

<router id="standard">    
    <route frontName="hello" id="hello">
        <module name="HelloWorld_Hello"/>
    </route>
    <route frontName="blog" id="blog">
        <module name="HelloWorld_Hello"/>
    </route>
</router>

if you want to give them different layout you can do that from layout

frontName hello

Namespace/Modulename/view/frontend/layout/hello_index_index.xml

frontName blog

Namespace/Modulename/view/frontend/layout/blog_index_index.xml

by default they will go to same controller/index/index.

Related Topic