Query parameters deleted from URL upon navigation
Answered
Tibetan Mastiff posted this in #help-forum
Tibetan MastiffOP
Navigatin to url for example /en/signup?referral=test first time recieved the "test" value but there is a refres and the value is removed from the URL and its empty.
27 Replies
@Tibetan Mastiff Navigatin to url for example /en/signup?referral=test first time recieved the "test" value but there is a refres and the value is removed from the URL and its empty.
are you using a middleware for your language stuff? If so, the middlemare might remove the query param
Tibetan MastiffOP
Correct, I was looking for an issue there, but I was not able to find if the problem is actually there
Why would it return it at first and then remove it?
This happens only if I insert URL directly into the browser. If I change the query params via router for example it works just fine
The query params are deleted, because you don’t add them here: (see attached). You might want to add the query Params there as well to prevent deletion
Tibetan MastiffOP
but that part of the code is not called if I access /en/something directly and they are deleted anyway
I tried doing this: request.nextUrl.pathname =
but that does not help
/${locale}${pathname}${request.nextUrl.search};but that does not help
that will do: en/signup%3Freferral=222?referral=222
The request object already contains the data about the query params
hm ok, can you provide a reproduction from the error via jsfiddle or https://codesandbox.io/ . Like that we will be able to help you better
@Tibetan Mastiff you want to delete the param on redirect or want to keep it during redirect?
@B33fb0n3 hm ok, can you provide a reproduction from the error via jsfiddle or https://codesandbox.io/ . Like that we will be able to help you better
Tibetan MastiffOP
There is no error unfortunately (that would help).
1. I want to be able to past a link containing params (/en/signup?referral=something) to the browser and be able to access these params.
Actual behaviour:
1. I can console log it once, but there seems to be a re-render on which these params are deleted
1. I want to be able to past a link containing params (/en/signup?referral=something) to the browser and be able to access these params.
Actual behaviour:
1. I can console log it once, but there seems to be a re-render on which these params are deleted
@Mainak <@409785205411282945> you want to delete the param on redirect or want to keep it during redirect?
Tibetan MastiffOP
Hello, issue described in message above
In that page and client components I have nothing that should change the URL. I have this issue also on static pages, that contain only texts, that makes me believe its either Middleware or Layout or Next.js internal issue
Same behaviour in DEV and PROD
@Tibetan Mastiff There is no error unfortunately (that would help).
1. I want to be able to past a link containing params (/en/signup?referral=something) to the browser and be able to access these params.
Actual behaviour:
1. I can console log it once, but there seems to be a re-render on which these params are deleted
ah yea, no error. I mean unexpected behavior. It seems like you cant reproduce it inside a clean enviorement. I guess then I can't help you more, because it looks like a local issue
@B33fb0n3 ah yea, no error. I mean unexpected behavior. It seems like you cant reproduce it inside a clean enviorement. I guess then I can't help you more, because it looks like a local issue
Tibetan MastiffOP
Let me try to reproduce in local enviroment
@Tibetan Mastiff Let me try to reproduce in local enviroment
Better would be to reproduce it in a cloud Environment like https://codesandbox.io/
@Tibetan Mastiff can you share the link of the cloud reproduction?
@B33fb0n3 <@409785205411282945> can you share the link of the cloud reproduction?
Tibetan MastiffOP
Hello, found an issue, it was indeed the translations feature, but it was on my side. Thanks for support.
@Tibetan Mastiff Hello, found an issue, it was indeed the translations feature, but it was on my side. Thanks for support.
Can you share the full solution, so everyone else who encounter this issue will know the solution?
@Tibetan Mastiff?
Tibetan MastiffOP
Hello, the issue was project specific. It was becuase of my implementation of language switcher. Which used this hook:
Tibetan MastiffOP
I had to add the last part queryString to the URL
Answer