Prevent scroll to top after router.replace()
Unanswered
Gharial posted this in #help-forum
GharialOP
EDIT:: ANSWER AT BOTTOM
I have implemented: router.replace('/new-page', undefined, {scroll: false}) for a param query. The query works but the page scrolls to the top. How can this be avoided? Here is more code just in case:
Any help appreciated. Thank you
ANSWER:
EDIT::: TO answer my question, the solution was:
<Select onValueChange={value => router.replace(
I have implemented: router.replace('/new-page', undefined, {scroll: false}) for a param query. The query works but the page scrolls to the top. How can this be avoided? Here is more code just in case:
export function ProductSort() {
console.log("ProductSort rendering");
const router = useRouter();
console.log("Router:", router);
return (
<div className="flex items-center">
<Select onValueChange={value => router.replace(value, undefined, {scroll: false})}>
<SelectTrigger className="sm:w-[180px]">
etc etc etcAny help appreciated. Thank you
ANSWER:
EDIT::: TO answer my question, the solution was:
<Select onValueChange={value => router.replace(
${value}#store, undefined, {scroll: false})}>