Access full pathname

I am using the dcc.location and updating the value of the pathname when a value from a dropdown is selected.

This works great
@app.callback(
Output(‘this_url’, ‘pathname’),
inputs=[Input(‘my_dropdown’, ‘value’)])
def change_url(value: str) -> str:
local_url = f"/?value={value}"
return local_url

However, the problem is that when someone accesses from the url like this -> “https://mywebsite.com/?value=my_value” dash interprets the “?value=my_value” as part of the global pathname, so, when the callback is called by changing the value of the dropdown, I start getting this types of URLs -> “https://mywebsite.com/?value=my_value?value=my_value” … “https://mywebsite.com/?value=my_value?value=my_value?value=my_value

Any idea how to limit this to only one ?value=my_value . ???

Thanks!

Instead of pathname, I think you might want either the search or href props. Check out the docstring of Location for some more details.

using href made the job!

thanks!

1 Like