Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NextJs: attempted to hard navigate to the same URL error while passing query string

I'm working on NextJs version 13.0.2 and ReactJs version 18.2.0. I want to pass a query string in the URL but I get:

Error: Invariant: attempted to hard navigate to the same URL /@workamirdanesh?w=true http://localhost:3000/@workamirdanesh?w=true

Everything is ok when I go to the http://localhost:3000/@workamirdanesh URL. But when I add a query string like: ?w=true and it becomes: http://localhost:3000/@workamirdanesh?w=true, I get the above error.

How can I solve it and what is the problem here? obviously, the query string should not throw an error and should load the page with the URL before the query string.

UPDATE: I updated the NextJs version to 13.0.7 and the problem still exists.

like image 319
Amir Danesh Avatar asked Dec 08 '25 10:12

Amir Danesh


1 Answers

Got the same issue

Unhandled Runtime Error
Error: Invariant: attempted to hard navigate to the same URL /listings/ http://localhost:3000/listings/

Seems to be occurring when returning to a 404 page, so if the page returns 404 and you click on the same link, it will result to the above error.

like image 139
Live Software Developer Avatar answered Dec 10 '25 22:12

Live Software Developer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!