dcc.Location doesn't correspond with window.location.href


I’m trying to make my Dash app to load with a some selected parameters using the URL query string.
So I have a callback which has this Input: [Input('url', 'pathname')], so it will do some output depending on the url.
However, dcc.Location seems to not correspond with the actual browser URL (window.location.href) since this callback gets empty string when is loaded for first time in the app, no matter what is written in the browser address bar.
It does work if I change the url using another dash component which modifies the url, pathname (i.e. this Output: Output(‘url’, ‘pathname’).
Moreover, if I load a url with something already written is query string, let’s say: mydomain.com/app?foo and then I activate the callback which writes ‘foo’ to the pathname, the actual result in the address will be: mydomain.com/app?foofoo, but the receiving function callback for [Input('url', 'pathname')] gets only one foo; instead of two as the user is seeing.

You use the pathname part of the url which is everything after the domain (eg: /my-app). You need the href prop instead.

1 Like

That’s right. Thank you!