✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Routing to new URL from a callback

Here is the scenario. The user will be on index page("/index") initially and user has upload functionality here and as soon as upload(I know how to how check the process is done or not) is done I want automatic routing to another URL("/uploaded").

To read current URL, I know that we can use dcc.Location, but how to route to a new URL from current URL.

I am having similar scenario. So far I was not able to change the URL from a callback. Hope someone will help here…

I am able to figure out. You just have to give a callback to a hidden div and return dcc.Location with updated pathname. here is my callback that worked. In code below I am checking if all files are uplaoded successfully and then routing to different URL(in my case routing from “/index” to “/newurl”.

    Output("temporary-store", "children"),
    [Input('upload-data', 'contents')]
def display_page(contents):
    if contents is not None:
        return (dcc.Location(pathname="/newurl", id="something-id")

The above was giving: Expected the output type to be a list or tuple
Once I put the dcc.Location in a list, it worked.

return [dcc.Location(pathname="/newurl", id="something-id"]


I had an extra comma for the Input. edited the code. Thank you.

I see one issue here. The data I had in hidden divs is all gone in the new URL. Not sure how to prevent data loss from happening in the divs.

Have you tried to set refresh=False?

return [dcc.Location(pathname="/newurl", id="something-id", refresh=False)]

if I do refresh=false, it is not routing to new URL/page at all.
I am browsing through the forum and came across this. Will have to explore if it works.