Back to SiteRouter class

Method getComponentRouter

public \Joomla\CMS\Component\Router\RouterInterface
getComponentRouter
(mixed $component)
Get component router
Parameters
  • string $component Name of the component including com_ prefix
Returns
  • \Joomla\CMS\Component\Router\RouterInterface Component router
Since
  • 3.3
Class: SiteRouter
Project: Joomla

Method getComponentRouter - Source code

/**
 * Get component router
 *
 * @param   string  $component  Name of the component including com_ prefix
 *
 * @return  RouterInterface  Component router
 *
 * @since   3.3
 */
public function getComponentRouter($component)
{
    if (!isset($this->componentRouters[$component])) {
        $componentInstance = $this->app->bootComponent($component);
        if ($componentInstance instanceof RouterServiceInterface) {
            $this->componentRouters[$component] = $componentInstance->createRouter($this->app, $this->menu);
        }
        if (!isset($this->componentRouters[$component])) {
            $this->componentRouters[$component] = new RouterLegacy(ucfirst(substr($component, 4)));
        }
    }
    return $this->componentRouters[$component];
}