Get dcc.Location string

Hello,

I am trying to get the string of the path by using dcc,Location, but instead a list is being returned. Is there a way I can just get a string by using dcc.location

Example:

layout = html.Div([
    dcc.Location(id="url1", refresh=True)
], id="404")
@app.callback(
    Output("url1", "pathname"),
    Input("404", "children")
)
def checkID(url):
    global df
    print(url)
    url = str(url)
    url = url.replace("/", "")
    for i,row in df.iterrows():
        crimeId = str(row.CrimeID)
        if url == crimeId:
            return mapPublic.layout
    raise PreventUpdate

What is printed:

[{'props': {'id': 'url1', 'refresh': True, 'pathname': '/4102021Chelmsford', 'href': 'http://10.0.0.178:8050/4102021Chelmsford', 'hash': '', 'search': ''}, 'type': 'Location', 'namespace': 'dash_core_components'}]

Thank you

1 Like

does this help?

url[0]["props"]["href"]
1 Like

Thank you, that helped, but I later noticed I had switched up my Input/Output accidentally, causing my url variable to equal the dcc.Location component, not the pathname