# dcc.Location and navigating without full page reload

**URL:** <https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068>\
**Category:** Dash Python\
**Created:** [April 3, 2023, 2:14am UTC](https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068 "2023-04-03T02:14:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inci](https://avatars.discourse-cdn.com/v4/letter/i/e47c2d/32.png) [@Inci](https://community.plotly.com/u/Inci)\
**Post date:** [April 3, 2023, 2:14am UTC](https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068/1 "2023-04-03T02:14:15Z")

</div>

I’m using a callback to update a location component, and wanting to navigate in an ‘SPA’ way, without a full page reload.

`dcc.Location(id='app-location', refresh='callback-nav')`  
(I have also tried =True, or =False)

I’ve tried reading the docs ([Location | Dash for Python Documentation | Plotly](https://dash.plotly.com/dash-core-components/location)) however it’s a tad confusing, how exactly it’s meant to function, and how I’m meant to use it.

Thanks for any help!

Inci

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [April 3, 2023, 2:35am UTC](https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068/2 "2023-04-03T02:35:50Z")

</div>

Hi @Inci

What version of dash are you using? This requires dash\>=2.9.0:

`dcc.Location(id='app-location', refresh='callback-nav')`

If you are on the most current version and it’s not working, could you post a minimal example that replicates the issue?

---

<div class="post-metadata">

**Author:** ![Inci](https://avatars.discourse-cdn.com/v4/letter/i/e47c2d/32.png) [@Inci](https://community.plotly.com/u/Inci)\
**Post date:** [April 3, 2023, 7:16am UTC](https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068/3 "2023-04-03T07:16:29Z")

</div>

Oh. That’s awkward, I didn’t realise it was 2.9+, or realise 2.9 was even out yet.

Thanks for pointing that out, 2.9 also seems to have a whole raft of awesome features added too.

Thanks for that!

---

<div class="post-metadata">

**Author:** ![Sohibjon](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sohibjon](https://community.plotly.com/u/Sohibjon)\
**Post date:** [April 3, 2023, 10:20am UTC](https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068/4 "2023-04-03T10:20:36Z")

</div>

here is the minimal code how to redirect the user if , but can’t do it without refreshing the page

```auto
import dash 
from dash import html, Input , Output, dcc 
import dash_bootstrap_components as dbc

app = dash.Dash( __name__ )

app.layout = html.Div([
    html.Div(id="hidden_layout_for_redirect"),
    dbc.Button("Apply",id="button")
])

@app.callback(
    Output("hidden_layout_for_redirect", "children"),
    Input("button", "n_clicks")
)
def test(n_click):
    if dash.ctx.triggered_id =="button":
        return dcc.Location(id="someid", href="/dashboard", refresh="callback-nav")
    else:
        raise dash.exceptions.PreventUpdate
    

if __name__ == " __main__":
    app.run_server(debug=True)

```

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [April 3, 2023, 1:07pm UTC](https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068/5 "2023-04-03T13:07:29Z")

</div>

@Sohibjon

The `dcc.Location` must be in the layout. And if it’s a multi-page app, it needs to be in the main `app.py`

Try it like this:

```auto

import dash
from dash import html, Input, Output, dcc
import dash_bootstrap_components as dbc

app = dash.Dash( __name__ )

app.layout = html.Div([
    dcc.Location(id="url", refresh="callback-nav"),
    html.Div(id="hidden_layout_for_redirect"),
    dbc.Button("Apply", id="button")
])

@app.callback(
    Output("url", "href"),
    Input("button", "n_clicks")
)
def test(n_click):
    if dash.ctx.triggered_id == "button":
        return "/dashboard"
    else:
        raise dash.exceptions.PreventUpdate

if __name__ == " __main__":
    app.run_server(debug=True)

```

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [April 3, 2023, 1:12pm UTC](https://community.plotly.com/t/dcc-location-and-navigating-without-full-page-reload/74068/6 "2023-04-03T13:12:54Z")

</div>

Hi @Inci - not awkward 🙂 2.9.0 was released very recently and the announcement is coming soon.

I think this will be one of my favorite new releases - there are tonnes of amazing new features in 2.9 🎉
