Gatsby: Gatsby rewrites hrefs?

Created on 6 Mar 2019  路  8Comments  路  Source: gatsbyjs/gatsby

Hi there,
we are unable to write a simple link using <a href=""> and passing query params, I do wonder if Gatsby rewrites for some reason the links strimming out the params.

We can't use from Gatsby since these are external links.

I looked in previous issues and I can't find much. Is this an expected behaviour?

Thanks

question or discussion

All 8 comments

@aterreno what exactly does your a look like? Could you provide a reproduction?

We shouldn't be doing anything here to "re-write" any of your content, we rely on React serializing to HTML for much of this.

@DSchau I'll try to reproduce with a reproduction, the issue is similar to this https://github.com/gatsbyjs/gatsby/issues/9815 but in this case the answer was to use a which would not work for us.

Reproduced! This is crazy! https://github.com/aterreno/gatsby-bug-repro

Try the app in local, it should work if you pass query params, then try the deployed version

https://stupefied-fermat-ce7a45.netlify.com/?channel=test

I wonder if it's possible that netlify strips for no reason the query params. Otherwise it must be the gatsby build...

screenshot 2019-03-06 16 24 00
screenshot 2019-03-06 16 23 55

One more finding: 100% not netlify fault, steps to reproduce:

yarn build
cd public
python -m SimpleHTTPServer 3000

screenshot 2019-03-06 16 29 20

To be clear, which link is manifesting the issue? Or are all of them?

Generally - GatsbyLink should not be used for _external_ links. It's for internal links to other pages within your application. If you open your console, you'll see warnings like "A page not found for " because you've used an external link.

As far as the search params, I _think_ that's an issue with hydration. The search param isn't known at build time, so you will likely want to tap into componentDidMount to grab the search params and update them statefully.

Does that make sense?

@DSchau spot on, thanks a lot, it's now fixed and working.

Woo hoo!

Glad to hear it :) Closing this out.

Thanks for using Gatsby 馃挏

This is very confusing issue, I faced the same one and it was not obvious at all to use componentDidMount for that :(

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theduke picture theduke  路  3Comments

andykais picture andykais  路  3Comments

rossPatton picture rossPatton  路  3Comments

mikestopcontinues picture mikestopcontinues  路  3Comments

dustinhorton picture dustinhorton  路  3Comments