How to create router file for a component of joomla. I am using Sef url in particular
-
What you tried doing yourself? – Phil Cooper Dec 29 '15 at 10:53
-
I used jroute::_('index.php?option=com_abc&view=def&ghi=102') an Url of component view . But There is SEF url is break after view URL :mydomain.com/Sitename/abc/?view=def&ghi=102 – kailash Chandra Dec 29 '15 at 11:01
3 Answers
I was having the same issue and after trawling through the internet and only ever coming across answers like the one seen here ("see the documentation") which is really unhelpful in my opinion and of all the documentation that page is the most unhelpful.
Anyway I firstly ended up giving up on the "component router", I could get it to easily work to build routes but found that it wouldn't parse anything and without having both working, it was pointless continuing.
In the end I decided going down the plugin path was the answer and found this really good plugin here from Daniel Calviño Sánchez.
I then ended up finally coming across some joomla documentation here that IS perfect and will get you exactly where you need to go.
I personally think that the joomla router needs alot of work and saw there are lots of ideas from people wanting it upgraded. I found using a plugin in the end was the easiest path and was the better solution all round.
I would be happy to discuss with anyone as to why my component router wouldn't call its parse method as if that actually worked, it would've been my first choice.
Hope this helps.

- 591
- 6
- 15
Unfortunately documentation didn't provide a way to register my router so I found an alternative solution.
The router.php is actually a Joomla\CMS\Router\SiteRouter
You can use the $this
variable, even if you think you're not within a class.
This can be checked by performing var_dump($this)
There are two methods that can be used.
$this->attachBuildRule(function(){
// build rule code
});
$this->attachParseRule(function(){
// parse rule code
});
If you are using an object implementing RouterInterface the callbacks are the following
$this->attachBuildRule([$myRouter, 'build']);
$this->attachParseRule([$myRouter, 'parse']);
The methods expect a callable and a STAGE, see Router::PROCESS_*
constants in namespace Joomla\CMS\Router
If you are using PHPStorm you can write the following code for assistance:
/**
* @var $this Joomla\CMS\Router\SiteRouter
*/

- 645
- 6
- 15
-
1If you are able to provide support for Joomla questions, please join us at JoomlaStackExchange and see if you can help to resolve some of the unresolved questions. Thanks. – mickmackusa Dec 05 '18 at 10:40
Check out this documentation .
It describes very precisely how to create a Route and how the Routing works in Joomla.
Also check out com_content/router.php
as an example

- 601
- 1
- 4
- 22