Adding friendly URLs to our component
Friendly URLs in web development are a two-sided problem. On the one hand, when showing a URL to your users, you need to translate all your ugly links with parameters into words to make them more friendly. These words usually match the name of the page we are showing, and we call them slugs or aliases. For example, in the https://YourDomain.com/joomla-4-extension-development URL, the slug is joomla-4-extension-development
.
The second problem starts when your users request a friendly URL, and you need to translate it into parameters for your Joomla! site to understand the request.
To handle these problems in Joomla!, we need to add a so-called router to our component. In Joomla!, we inject the router as a service.
To do this, edit the src/component/admin/services/provider.php
file and add the following namespaces:
src/component/admin/services/provider.php
use Joomla\CMS\Extension\Service\Provider\RouterFactory; use Joomla\CMS\Component...