gatsby-plugin-intl icon indicating copy to clipboard operation
gatsby-plugin-intl copied to clipboard

switching languages seems to not stay on the same route and scroll position...

Open rchrdnsh opened this issue 6 years ago • 4 comments

Hi Everybody,

In an app I'm working on I have two languages and buttons that switch between them. But what seems to be happening now is that when I switch languages the site redirects to the homepage and scrolls to top, rather than staying on the same page and keeping the same scroll position, which is the desired behavior.

Any ideas why this might be the case?

This is the code for my language switching buttons:

const Language = () => {
  return (
    <>
      <IntlContextConsumer>
        {({ languages, language: currentLocale }) =>
          languages.map(language => (
            <LocaleButton
              key={language}
              onClick={() => changeLocale(language)}
            >
              {languageName[language]}
            </LocaleButton>
          ))
        }
      </IntlContextConsumer>
    </>
  )
}

The <LocaleButton> is just a few basic visual styles.

rchrdnsh avatar Aug 26 '19 23:08 rchrdnsh

Is there any solution for this?

vlknhslk avatar Feb 16 '20 21:02 vlknhslk

not that i know of...

rchrdnsh avatar Mar 10 '20 01:03 rchrdnsh

I have this same problem.

easherma avatar Jul 02 '20 19:07 easherma

@rchrdnsh @easherma @vlknhslk I have to say this starter package sounded like a good solution but there are no discussions around it. we have a basic discussion just to set up and rest are left on the user.

Few things to consider -

1 - What if I have few pages which I want to have multiple urls and not for the whole site? 2 - I guess all these are done by client side routing which may affect the SEO, Any solution for that?

Anyways, It was a good effort but it fails to fit as a broad solution. I feel gatsby community should standardise the localisation. Thanks.

Am1tgupt4 avatar Sep 21 '20 11:09 Am1tgupt4