The following multi-page app works just fine.
import dash
from dash import Dash, html, dcc
layout_1 = html.Div([
html.H1('The Page 1 Title'),
dcc.Link('Go to Page 2', href='/page-2')
])
layout_2 = html.Div([
html.H1('The Page 2 Title'),
dcc.Link('Go to Page 1', href='/')
])
app = Dash( __name__, use_pages=True, pages_folder='')
dash.register_page("page-1", path='/', layout=layout_1)
dash.register_page("page-2", layout=layout_2)
app.layout = html.Div( dash.page_container )
if __name__ == '__main__':
app.run_server(debug=True)
However, if I capitalize page-2
to Page-2
in both locations it results in an error 404 page not found. Looking further, it appears register_page
passes the module argument to an _infer_path
function which does some string cleaning (e.g., lower case, replace _ with -).
I know capital letters are a bit odd in this context, but I had a student with this issue and it was a PITA to solve. I know it is also possible to manually set the path in register_page
with the path=
argument — dash.register_page("Page-2", path="Page-2", layout=layout_2)
— but is that really the desired behavior? If so, should it be mentioned in the docs somewhere? Am I missing something?
Thanks in advance!