I'm trying to create a friendly URL for a custom component but i can't manage to find a solution. I have tried JRoute but it hasn't worked out for me (probably i'm not doing it right). Does anybody have any idea? I have created the router file and i read the documentation but i couldn't understand.


i wanted it to be



after implementing all methods i get the following error:

Argument 1 passed to ComponentRouter::__construct() must be an instance of CMSApplication or null

My code is:

class ContentRouter implements Joomla\CMS\Component\Router\RouterInterface


    public function __construct(CMSApplication $app = null, AbstractMenu $menu = null)
        $category = new RouterViewConfiguration('category');
        $article = new RouterViewConfiguration('article');
        $article->setKey('id')->setParent($category, 'catid');

        parent::__construct($app, $menu);

        $this->attachRule(new MenuRules($this));
        $this->attachRule(new StandardRules($this));
        $this->attachRule(new NomenuRules($this));

    /* the other methods go here


I'm not sure if Joomla\CMS\Component\Router\RouterInterface is the right class to be implement since there's no many examples but i followed along with the tutorial, i have implemented all the 3 methods and i yet get that error.

  • 1
    Please don't edit just to change i to I, but if you make any more meaningful edits, please improve the grammar in the same edit.
    – mickmackusa
    Apr 3 '20 at 12:29
  • Sorry, sometimes i don't realise my mistakes and then i come to correct some minor errors. By the way, if you have any idea i will be very much appreciated. Apr 3 '20 at 12:33
  • 1
    No worries, I will guide you through your early days here. As for your issue, I will leave you in the very capable hands of Sharky.
    – mickmackusa
    Apr 3 '20 at 12:36
  • 1
    Some more info on the new router at groups.google.com/forum/#!topic/joomla-dev-general/YnILNx_Lmeg. If you can't get it to work, then you can always try going back to the old router. A simple example using it is in docs.joomla.org/J3.x:Developing_an_MVC_Component/…. (I tried getting the new router to work for my component, but failed). Apr 3 '20 at 21:25
  • 1
    @Thiago, yeah, in my opinion, the big problem with a rule-based router like the new Joomla one is that it's pretty impossible to debug if you can't get it to work. If you're in that position then I'd recommend going with the old one. At least it's going to be possible to get it working in the end of the day. Apr 4 '20 at 20:21

You have to create a router for your component for JRoute::_() to do anything. See Supporting SEF URLs in your component documentation. I suggest looking specifically at Simple View-based Example which uses a new way of working with routing.

  • Thank you for your answer but i had tried this and i had no success. The documention isn't clear to me (it might work out for others) but i have had hard times trying to understand the content of that page. I found that quite unhelpful. It didn't even say the class i should extend. I tried to implement the functions and always get an error such as abstract class errors and so on. Apr 3 '20 at 10:40
  • I tried to implement the Joomla\CMS\Component\Router\RouterInterface class but it gives me an error ComponentRouter contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods i don't know what methods are those. Apr 3 '20 at 11:25
  • I mean it says the name of the methods but how can i implement them? There's no example. Apr 3 '20 at 11:34
  • 1
    If you want to use standard routing, the class to extend is Joomla\CMS\Component\Router\RouterView. This is written in the linked documentation.
    – Sharky
    Apr 3 '20 at 14:09
  • 1
    You need to import some classes like Joomla\CMS\Application\CMSApplication.
    – Sharky
    Apr 3 '20 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.