When trailingSlash is "always", anchor links in the <Link> component have a "/" preffix. #36071
Closed
2 tasks done
Labels
type: bug
An issue or pull request relating to a bug in Gatsby
type: question or discussion
Issue discussing or asking a question about Gatsby
Preliminary Checks
Description
If the trailingSlash option is set to "always" - Gatsy adds "/" to Link elements if they are an anchor link.
The issue is fixed when trailingSlash is set to the current default - "legacy". However, in gatsby v5 the legacy option will be removed, the default will be set to always, and the
gatsby-plugin-force-trailing-slashes
plugin will be deprecated.I believe the issue comes in this line:
gatsby/packages/gatsby-link/src/index.js
Line 67 in ccf70da
If the path is no absolute (meaning it doesn't start with any of the following:
//
,http://
,https://
), and it doesn't (it starts with a#
) - we callabsolutify(path, relativeTo)
Reproduction Link
https://github.com/LlaziG/gatsby-link-anchor-issue/
Steps to Reproduce
nvm use
- to select a node version compatible with gatsbynpm run dev
- to start the server in dev modeExpected Result
Clicking on the anchor link should scroll down the page and the final URL should be:
localhost:8000/test/#sectionOne
The URL in the rendered element should be "#sectionOne"
Actual Result
It redirects to the index page, the actual URL in the end is:
localhost:8000/#sectionOne
The URL in the rendered is actually "/#sectionOne"
Environment
Config Flags
This is my gatsby-config.js:
The text was updated successfully, but these errors were encountered: