Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
Next.js — router.push scrolls page to the top despite scroll option set to false

I am using Next.js' built-in internationalisation features to change my app's language and everything is working perfectly except for one undesirable behaviour:

Calling the changeLanguage function results in the page scrolling to the top in spite of setting the router's scroll option to false.

Please note that Next.js - router.push without scrolling to the top and Next.js maintain scroll position when page Routing did not solve my issue.

import { useRouter } from "next/router";
import Select, { components } from "react-select";

const LanguageToggler = () => {

  const router = useRouter();
  const { locale, pathname, locales, asPath } = router;

  const changeLanguage = (e) => {
    const locale = e.value; // is equal to one of these values: ['en', 'sv', 'ru', 'fr']
    router.push(pathname, asPath, { locale }, { scroll: false });
  };

 return (
      <Select
        ...irrelevant
        onChange={changeLanguage}
        components={{
          Option: CustomSelectOption,
        }}
      />
    )
};

export default LanguageToggler;

P.S. The react-select library is used to display a dropdown list of flags, clicking each flag summons changeLanguage to update the locale accordingly.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Next router.push accepts three parameters.

router.push(pathname, asPath, { locale }, { scroll: false });

should be

router.push(pathname, asPath, { locale, scroll: false });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!