wiziple / gatsby-plugin-intl

Gatsby plugin that turns your website into an internationalization-framework out of the box.
http://gatsby-starter-default-intl.netlify.com
325 stars 178 forks source link

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

Open rchrdnsh opened 5 years ago

rchrdnsh commented 5 years ago

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.

vlknhslk commented 4 years ago

Is there any solution for this?

rchrdnsh commented 4 years ago

not that i know of...

easherma commented 4 years ago

I have this same problem.

amitkrgupta094 commented 4 years ago

@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.