Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

### Fixed
- [#4169](https://github.com/plotly/dash/pull/4169) Fix the inferred path of a page whose module name contains the pages folder name: `pages/landing_pages.py` no longer gets `/` and `pages/subpages/report.py` no longer gets `/report`. Fixes [#4168](https://github.com/plotly/dash/issues/4168).

## [4.5.1] - 2026-11-19

### Removed
Expand Down
4 changes: 3 additions & 1 deletion dash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def _infer_path(module_name, template):
if template is None:
if CONFIG.pages_folder:
pages_module = str(Path(CONFIG.pages_folder).name)
# Match the folder name as whole dotted parts, not as a substring.
path = (
module_name.split(pages_module)[-1]
f".{module_name}.".rpartition(f".{pages_module}.")[-1]
.strip(".")
.replace("_", "-")
.replace(".", "/")
.lower()
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/multi_page/test_pages_infer_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import dash
from dash import Dash


def test_pain001_infer_path_module_contains_folder_name(dash_duo, clear_pages_state):
# "overviews" and "reviews" contain the pages folder name "views".
app = Dash(__name__, use_pages=True, pages_folder="views")
dash_duo.start_server(app)

paths = {page["module"]: page["path"] for page in dash.page_registry.values()}
assert paths == {
"views.overviews": "/overviews",
"views.reviews.latest": "/reviews/latest",
}

dash_duo.wait_for_page(f"{dash_duo.server_url}/overviews")
dash_duo.wait_for_text_to_equal("#text_overviews", "text for overviews")

dash_duo.wait_for_page(f"{dash_duo.server_url}/reviews/latest")
dash_duo.wait_for_text_to_equal("#text_latest", "text for latest")

assert dash_duo.get_logs() == [], "browser console should contain no error"
7 changes: 7 additions & 0 deletions tests/integration/multi_page/views/overviews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dash
from dash import html


dash.register_page(__name__)

layout = html.Div("text for overviews", id="text_overviews")
7 changes: 7 additions & 0 deletions tests/integration/multi_page/views/reviews/latest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dash
from dash import html


dash.register_page(__name__)

layout = html.Div("text for latest", id="text_latest")
3 changes: 3 additions & 0 deletions tests/unit/pages/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
str(THIS_DIR / "custom_pages"),
"/chapter-1/page-1",
),
("pages.landing_pages", None, str(THIS_DIR / "pages"), "/landing-pages"),
("pages.subpages.report", None, str(THIS_DIR / "pages"), "/subpages/report"),
("views.overviews", None, str(THIS_DIR / "views"), "/overviews"),
# can this even be called with CONFIG.pages_folder set to None?
("dir.my_page", None, None, "/dir/my-page"),
# is this behaviour right? why is filename ignored when template has a value?
Expand Down