It's probably best to run a backup before making any changes.
To narrow down the problem, try disabling URL Rewriting and SEF and renaming .htaccess to .htaccess.old. If this helps, try re-enabling the default .htaccess file, then SEF and then URL Rewriting, clearing the cache and checking the website after each step.
Clear the Joomla ...
JRoute::_() doesn't find anything. It just turns non-SEF links into SEF. How that is done depends on your component's router. Unless your component implements modern routing (introduced in 3.7, I think), you do need to find the Itemid.
Prior to modern routing, each Joomla core component used its own route helper class to lookup menu items, find the IDs and ...
Since 3.9 there's Joomla\CMS\Router\Route::link() method which takes client (site or administrator) as first argument.
$link = 'index.php?option=com_content&view=article&id=1';
echo '<a href="' . JRoute::link('site', $link) . '">Test</a>';
If you have the article object available, you should use ContentHelperRoute::getArticleRoute() and ...
So... I made this far too difficult for myself.
The answer is that I had a space in my code, right after the opening img src=" this was causing the Joomla SEF plugin to prefix my domain URL in the space.
console.log('<img src=" '+url+' ">');
Hope this saves someone else a few ...
To get SEF URL, pass non-SEF URL through JRoute::_(). To get non-SEF URL, you can use ContentHelperRoute::getArticleRoute().
// Load route helper class.
JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');
// Build non-SEF URL.
$nonSefLink = ContentHelperRoute::getArticleRoute($article->id . ':' . $article-&...
It's a bit unclear what's your exact goal and how you are going to use whatever possible answer you are going to get.
Will you have all previous SEF URLs changed? Will you do a search and replace inside the database for all old links of the content? And how you could combine a possible API usage with the database operations.
I think the whole task needs a ...