joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.78k stars 3.65k forks source link

Menu link as an URL to an in-page anchor ( ...#some-id) not always working from a submenu #44453

Closed BillyGeat closed 6 days ago

BillyGeat commented 1 week ago

The closed issue #43324 (Menu link URL to an in-page anchor ( ...#some-id) not working from a submenu) is not fully solved in Joomla 5.2.1.

If you add an anchor link to a page that is under a sub-menu, the resulting link does not work (error 404) as it is wrong created.

When the link is like https://website/article1 ("article1" is the Alias showing under the menu item in the administration) then the resulting link https://website/article1#jump-to-2 works.

But if there are sub-menu items like https://website/products/product1, it does not work because the resulting link is then like this

https://website/product1#jump-to-3 instead of the correct one https://website/products/product1#jump-to-3

The link in the menu is created as "System Links -> URL" and the link then is added as "product1#jump-to-3" (where "product1" is the Alias from menu administration again). Adding something like "products/product1#jump-to-3" does only work if SEF URLs are activated and working (not always the case on some environments).

Hackwar commented 6 days ago

I'm sorry, but that is expected behavior. You are using a relative URL and as it seems, you are expecting by simply referencing just the alias of something, you'd have a complete URL. Both unfortunately is not true. First of all, if you are using a URL which is not processed by the Joomla routing system (e.g. a URL starting with index.php?option=) you have to use absolute URLs, starting from the root of the domain, for example /product1. And besides that, the router expects a full URL path, like you described yourself: /products/product1. Since this is not a bug in Joomla, I'm closing this issue.

BillyGeat commented 6 days ago

OK, I thought, the alias is something like a unique identifier (from what I understood here: https://github.com/joomla/joomla-cms/issues/43324#issuecomment-2067811839), because it works for "flat" menu structures.

So as it looks now, there is no way to have anchor links in sub menus that work in both cases, with activated and not activated SEF URLs.

Hackwar commented 6 days ago

There are numerous ways, you can use the non-SEF URL with Itemid or you can just use the non-SEF URL consisting of just the Itemid, depending on what you want to do. But normally you wouldn't switch between SEF and non-SEF URLs.

BillyGeat commented 6 days ago

Yes, this is true, when it works with SEF URLs (best and wanted case) there is no need to switch between them. My issue was, that I had SEF URLs in my dev environment but on the prod server didn't work (then, but solved now). Thank you!