Joomla custom component - router not find alias

Joomla Asked by Lecraver on January 21, 2021

I am creating my own component.
Is it possible to transform:

Route::_('index.php?option=com_toto&view=tutu') into /somealiasinmenu?

(This alias can be found in a menu in the backoffice.)

I can do this:

  • link 1 /listAlias
  • link 2 /formAlias

When I click on listAlias, I can edit one row. With my router I have this url:

but I’d like this url /formAlias/123

How can I do that?

Here is my router.php:

function TotoBuildRoute(&$query)
    $segments = array();

        $segments[] = $query['view'];

        $segments[] = $query['id'];

    return $segments;

function TotoPlaceParseRoute($segments)
    $vars = array();

    if ($segments[0] === 'formviewname') {
        $vars['id'] = (int)strstr(end($segments), ':', true);
    $vars['view'] = $segments[0];

    return $vars;

One Answer

If I'm understanding you correctly, you have 2 menuitems on your site which have links /formAlias and /listAlias, and when you form an SEF URL using Route:_() then it gives you the wrong link; is that correct?

The way I believe Joomla routing works is that when you supply the parameters to Route::_() it goes through the site menuitems to compare the link attribute of each menuitem with the parameters you specify in your Route::_() call.

If it finds an exact match then it bases the SEF URL on the alias of that menuitem.

If it doesn't find an exact match, then the choice which Joomla makes will appear more random; I think the menuitem which the user is currently on will have a bearing.

Regardless of that, you can specify which menuitem Joomla should use in one of two ways (that I know of):

  1. By specifying the Itemid=xxx parameter in your Route::_() call (Itemid is the id of the menuitem you want to use)
  2. By changing the Itemid selected by Joomla in your custom router preprocess() function.

If you want to use the second option then there is an example in in the Custom Router section, where the code checks if the menuitem associated with the Itemid which Joomla routing has provided has the right language, and if not it tries to find a better menuitem, with the correct language.

You would need to do a similar thing to decide whether your formAlias or listAlias menuitem is more appropriate in each particular case. There is a guide to using the Joomla menuitem API at

Answered by Robbie Jackson on January 21, 2021

Add your own answers!

Related Questions

Add field to menu settings to output open graph image

1  Asked on December 30, 2021 by mano-meter


Edited css not updated in XAMPP

1  Asked on December 9, 2021 by advait-varma


Update from 3.9.x to 4.x

2  Asked on November 27, 2021 by lovntola


Other files overriding my template css with bootstrap?

1  Asked on November 19, 2021 by matthiasdunkel


Javascript accordion with anchors for joomla

1  Asked on November 5, 2021 by fruit_alchemist


Cannot Connect To MSSQL Server

3  Asked on September 5, 2021 by jamesmandatory


PlotALOT RSForm Query showing only one result

1  Asked on September 5, 2021 by gart


Getting module parameters in AJAX call using module id

1  Asked on September 5, 2021 by user1616338


Pop up AcyMailing subscription form

1  Asked on September 5, 2021 by ygiorgos


Override 3d party extension plugin method

0  Asked on September 5, 2021 by dmitry-zar


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP