Closed ezracelli closed 2 years ago
This is happening because in https://github.com/gatsbyjs/gatsby/blob/04ac1d6cb45df198ab01d119ce051d5f59b9ccb9/packages/gatsby-link/src/rewrite-link-path.js#L51 the isAbsolutePath
is false
and then it goes through https://github.com/gatsbyjs/gatsby/blob/04ac1d6cb45df198ab01d119ce051d5f59b9ccb9/packages/gatsby-link/src/rewrite-link-path.js#L13-L27
It returns with https://github.com/gatsbyjs/gatsby/blob/04ac1d6cb45df198ab01d119ce051d5f59b9ccb9/packages/gatsby-link/src/rewrite-link-path.js#L23
It should do the same as https://github.com/gatsbyjs/gatsby/blob/04ac1d6cb45df198ab01d119ce051d5f59b9ccb9/packages/gatsby-link/src/rewrite-link-path.js#L34-L37
We have unit tests for this that should also check this https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-link/src/__tests__/rewrite-link-path.js
Hi @LekoArts, would it be alright if I try to takcle this? I'm relatively new to open source development, but I think this would be a cool thing to work on.
Hi @LekoArts , If this is open please assign it to me it would like to give it a try
Close this. Fixed in #36798
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
Config Flags
N/A