anchor links have a trailing slash appended when using navigate()
with trailingSlash: "always"
#36742
Closed
2 tasks done
Labels
good first issue
Issue that doesn't require previous experience with Gatsby
help wanted
Issue with a clear description that the community can help with.
status: confirmed
Issue with steps to reproduce the bug that’s been verified by at least one reviewer.
topic: frontend
Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation)
type: bug
An issue or pull request relating to a bug in Gatsby
Preliminary Checks
Description
this is almost the same issue as #36071, but for the
navigate
function provided bygatsby
. in this case, extra slashes are appended to the URL rather than prepended (e.g.#hash
becomes#hash/
).the solution provided in #36071 (using native browser APIs) does extend to programmatic navigation, to some extent; for a hash update that pushes to the history stack and doesn't require updating the history state, it's possible to assign directly to
window.location.hash
. however, this gets a bit clunky for programmatic navigation using the History API, which is necessary for emulation of thereplace
orstate
options ofnavigate
.@gatsbyjs/reach-router
(poweringnavigate
+useLocation
) listens forpopstate
eventspopstate
events for programmatic calls tohistory.pushState
andhistory.replaceState
this combo means that a simple reactive hash change requires:
this pattern (calling
navigate()
with only a URL hash while usingtrailingSlash: "always"
) should be supported out-of-the-box, as Gatsby's own documentation might suggest it is.Reproduction Link
https://codesandbox.io/s/charming-feynman-frhw59
Steps to Reproduce
gatsby-config
propertytrailingSlash
to"always"
navigate("#hash")
from anywhereExpected Result
When calling
navigate("#hash")
, the page hash should change to#hash
Actual Result
When calling
navigate("#hash")
, the page hash changes to#hash/
Environment
System: OS: macOS 13.0 CPU: (10) arm64 Apple M1 Pro Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.17.1 - /private/var/folders/q9/63kh50rj6sg1qqhckjzwj3880000gp/T/xfs-1f9f3d4d/node Yarn: 4.0.0-rc.22 - /private/var/folders/q9/63kh50rj6sg1qqhckjzwj3880000gp/T/xfs-1f9f3d4d/yarn npm: 8.19.2 - ~/.nvm/versions/node/v16.17.1/bin/npm Languages: Python: 3.10.6 - /usr/local/bin/python Browsers: Chrome: 105.0.5195.125 Firefox: 98.0.2 Safari: 16.1
Config Flags
N/A
The text was updated successfully, but these errors were encountered: