Single Page App ("SPA") URL / Multi Page Support - Proposal and Development Preview
See original GitHub issueHello Dash Community!
I just published 2 new components under the pre-release channel that enable multi-page support.
dash_core_components.Locationcomponent.Locationrepresents the URL bar in the browser. Thepathnameproperty updates thepathnameof the browser, refreshing the page ifrefresh=True.dash_core_components.Linkcomponent.Linkis likehtml.Aexcept that it updates theLocation’spathnamedirectly, without refreshing the page (refresh=False). Likehtml.A, it takeshrefas a component. It doesn’t render any markup itself, it just adds an “click” handler to whateverchildrenwere passed into it.
With these two components, we can make single-page apps with multiple URLs in Dash. A “single-page app” means that the pages update without doing an entire page refresh.
Here is a really eximple example:
# pip install dash_core_components==0.5.3rc1
import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash()
app.layout = html.Div([
# This "header" will persist across pages
html.H2('Multi Page Dash App'),
# Each "page" will modify this element
html.Div(id='content-container'),
# This Location component represents the URL bar
dcc.Location(id='url', refresh=False)
], className="container")
@app.callback(
Output('content-container', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/':
return html.Div([
html.Div('You are on the index page.'),
# the dcc.Link component updates the `Location` pathname
# without refreshing the page
dcc.Link(html.A('Go to page 2 without refreshing!'), href="/page-2"),
html.Hr(),
html.A('Go to page 2 but refresh the page', href="/page-2")
])
elif pathname == '/page-2':
return html.Div([
html.H4('Welcome to Page 2'),
dcc.Link(html.A('Go back home'), href="/"),
])
else:
return html.Div('I guess this is like a 404 - no content available')
app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
if __name__ == '__main__':
app.run_server(debug=True)
You can try this out with
$ pip install dash_core_components==0.5.3rc1
I’ll keep this in the prerelease channel for the next week or so before adding it to 0.5.3 and including it in the documentation.
I think this is a pretty good solution to handling multiple URLs for now.
Happy to field any feedback on this 😃
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Single-Page Application vs Multiple-Page Application
In this post, you will learn which projects are better to develop as a single-page application (SPA) or multiple-page application (MPA).
Read more >Single Page vs Multi-Page Application – What are The Main ...
A single-page application is a more modern approach to app development. It was used by Google, Facebook, Twitter, etc. A SPA is an...
Read more >Single-page application vs. multiple-page application - Medium
It is just one web page that you visit which then loads all other content using JavaScript — which they heavily depend on....
Read more >multiple pages in Vue.js CLI - Stack Overflow
Vue.js projects are SPAs(single page applications). You only have one .html file in the entire project which is the index.html file you ...
Read more >Single-page App vs Multi-page Application: What to Choose
However, spa software development isn't such a good idea if you want to build a large web app with a pile of features....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I have merged this into
dash-core-componentsand updateddash-docsto use this pattern. A tutorial on this is now at https://plot.ly/dash/urls 😃Ah, perhaps it’s as simple as adding
app.config.supress_callback_exceptions=Trueto my aDash app? This seems to work now. Is there any potential gotchas of having callbacks applied to as of yet undefined elements aside from missing out on validation of IDs etc?