Router.replace() causes page reload
Unanswered
Atlantic menhaden posted this in #help-forum
Atlantic menhadenOP
I have a Next.js 14 app running as a Docker container on AWS ECS (Fargate) behind a load balancer. I just have a page with a table of items, where when I click one a modal opens and the query string params are updated using
When I visit the app via Cloudfront, when I click an item that should invoke router.replace(), the page reloads (unexpected). If I visit the load balancer via its DNS name directly and do the same, the page doesn't reload (expected). Has anyone else experienced this, or have any idea what might be causing it?
router.replace() from the useRouter hook from next/navigation (app router).When I visit the app via Cloudfront, when I click an item that should invoke router.replace(), the page reloads (unexpected). If I visit the load balancer via its DNS name directly and do the same, the page doesn't reload (expected). Has anyone else experienced this, or have any idea what might be causing it?
1 Reply
Atlantic menhadenOP
If anyone else has this problem, make sure you have set an origin request policy in Cloudfront that forwards all query strings to the origin (the Next.js server). This fixed it for me.