Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] anchor link doesn't work on pages #4312

Closed
zyhfish opened this issue Jun 5, 2024 · 8 comments
Closed

[BUG] anchor link doesn't work on pages #4312

zyhfish opened this issue Jun 5, 2024 · 8 comments

Comments

@zyhfish
Copy link
Contributor

zyhfish commented Jun 5, 2024

Oqtane Info

Version - 5.1.2
Render Mode - Static
Interactivity - Server
Database - SQL Server

Describe the bug

anchor link doesn't work on pages because there is base tag pointed to home page:

Expected Behavior

the anchor link should link to the anchor on the page.

Steps To Reproduce

  1. add html module on the page and edit with below content:
<a href="#test">Click Me</a>
<a id="test"></a>
<h1>Test me!</h1>
  1. click on the link.
@sbwalker
Copy link
Member

sbwalker commented Jun 6, 2024

@zyhfish we can't change the base tag as there are a variety of things which depend on it. Have you tried to specify the hyperlink as "/#test"? Have you tested to see if anchors work when navigating from a different page? I have a feeling that this issue is isolated to the home page which has a path of "/". For example on https://www.oqtane.org the menu is using anchors for various sections on the page ie. #about #features #showcase and it works fine.

@zyhfish
Copy link
Contributor Author

zyhfish commented Jun 6, 2024

Hi @sbwalker , the problem is anchor links on all other pages which link to home page.

@sbwalker
Copy link
Member

sbwalker commented Jun 6, 2024

@zyhfish if I am on the Blog page (https://www.oqtane.org/blog) and click on the About link in the menu (which links to the home page with path "/" and anchor #about) it works fine.

@zyhfish
Copy link
Contributor Author

zyhfish commented Jun 6, 2024

Hi @sbwalker , yes, that because the link is really want to link to the home page.

If you try to add a new blog with below content:

<a href="#test">Click Me</a>
<a id="test"></a>
<h1>Test me!</h1>

when click on the link, the expected behavior is scroll the page to the anchor, but the actually result is page will be redirected to the home page.

@sbwalker
Copy link
Member

sbwalker commented Jun 6, 2024

@zyhfish so the simple solution is if you want to link to an anchor, include the relative page path in the hyperlink:

<a href="/path#test">Click Me</a>

@zyhfish
Copy link
Contributor Author

zyhfish commented Jun 6, 2024

Yes, but the content editors will be confused and becomes hard to maintenance the content. for example if they have Table of contents on the page which contains many anchor links, then if the page path been changed, they have to modify all the links to update the path.

@sbwalker
Copy link
Member

sbwalker commented Jun 6, 2024

Blazor requires the specification of <base href="/" /> (https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-8.0&tabs=visual-studio#app-base-path) which causes issues with naked anchor tags (ie. "#anchor"). This problem is actually not specific to Blazor - it is a problem with many SPA frameworks, as many of them require a base href. There is no technical solution that I am aware of to resolve this as the browser will automatically prefix anchors with the base href value - which means the router will receive a value of "/#anchor" without any additional context of what the original page path was where the hyperlink was located. Without this context, the router parses the url and determines that the path is "/" - which in Oqtane is generally the home page path. So the only real solution is for content authors to include the page path in their hyperlink anchor specification (ie. "path#anchor").

@sbwalker
Copy link
Member

closing as I do not believe there is a solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants