Page doesn't get reloaded on a Location pathname change

A callback that handles Location looks as follow:
layout

    dash_app.layout = html.Div([
        dcc.Location(id='location', refresh=True),
        dbc.Nav(
            [
                dbc.NavItem(
                    dbc.NavLink(html.I(className="bi bi-box-arrow-right text-dark"),
                                id='logout-link',
                                href='/auth/logout'
                    ),

                )
            ],
            pills=True,
        ),
        page_container
    ])

callback

    @dash_app.callback(Output('location', 'pathname'),
                       Input('logout-link', 'n_clicks'),
                       State('logout-link', 'href'),
                       prevent_initial_call=True)
    def handle_logout(n_clicks, href):
        return href

When i click the component logout-link the location in an address bar gets actually changed, BUT page doesnā€™t get reloaded and this is wierd as before iā€™ve tried the same approach in different callbacks and it worked well when i simply return a new pathname

Hello @kvdm.dev,

It looks like your are returning to the pathname instead of the url.

Not sure if that will fix it or not.

You could also take a look at my logout flow from Flask_Login flow. I use a redirect in logout that redirects to login after 3 second.

You are a bit incorret, href property has to be returned. Thx anyway :+1: , pathname is not what reloads a page.
@dash_app.callback(Output('location', 'pathname'), => @dash_app.callback(Output('location', 'href'),

About 3 seconds. To be honest, it looks as a workaround, when a user is clicking logout one obviously expects to be logged out immidiately.

1 Like

Hello @kvdm.dev,

You changed from pathname to href? Is that correct, I believe that I recommended changing it from pathnameā€¦

Glad you got it working.

If you take a look here you can see how I perform the redirect, I return the pathname as ā€˜/loginā€™ to the pathname element:

Yes, in the post above you can see two code lines
before

@dash_app.callback(Output('location', 'pathname')

after

@dash_app.callback(Output('location', 'href'),

U said in the first reply ā€œinstead of the urlā€ and iā€™ve got it literally as the property Location.url which doesnt exist, thatā€™s why i found it incorrect.

Another thing you can do is, external_link=True, this will trigger the page to refresh, which should then log the user out.

With dcc.Link, this is refresh=True.