Use URL query strings with single-page app

I have a single page Dash app and I want to use the query strings to modify my layout via the URL. I can make it work for multi-page apps using the kwargs of the layout function, but for some reason it does not work for a single-page app. Is this the intended behavior?

I found a workaround to be to create a pages folder with an empty file and register this page via the with path='/', and using the layout kwarg of the register_page function. That way, my app stays “single-page”, but it still implies creating a pages folder.

I believe there should be a way to make it work with this minimal example. For now it always will print 0, whatever the query strings are:

from dash import Dash, html

app = Dash(__name__)

def layout(n=0):
    return html.Div(n)

app.layout = layout

if __name__ == '__main__':


Hi @tcharland13

The functionality to pass the query strings and (and path variables) to the layout is a Pages feature.

You don’t need to create a pages folder - just set it to ""

app = Dash(__name__, use_pages=True, pages_folder="")

You can register the layout as a page like this, then display it in dash.page_container:

dash.register_page("home", layout=layout, path="/")

app.layout = html.Div(dash.page_container)

Find a full example here:

1 Like