Skip to content

Commit 5843073

Browse files
authored
Pro 9684 static path (#5509)
* Update Vue component for statis: true * Add changeset
1 parent 99d2f8f commit 5843073

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

.changeset/early-eyes-open.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"apostrophe": patch
3+
---
4+
5+
Fixed `piecesFilters` navigation (with `static: true`) reverting to the unfiltered index when logged in and an editor had clicked Edit at least once. It now recognizes filter path segments appended to the context doc's URL and preserves both the browser URL and the correctly filtered content on refresh.

packages/apostrophe/modules/@apostrophecms/admin-bar/ui/apos/components/TheAposContextBar.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,15 @@ export default {
591591
// Slug changed, change browser URL to reflect the actual url of the doc
592592
doc._url = doc._url + (window.location.search || '');
593593
history.replaceState(null, '', doc._url);
594+
} else {
595+
// No genuine slug change, e.g. the current path is just the
596+
// context doc's canonical URL with extra path segments appended
597+
// (piecesFilters paths generated by `static: true`). Fetch
598+
// content from the actual current browser URL rather than the
599+
// bare doc._url, otherwise any filter path segments and query
600+
// string driving the current view would be lost and we'd render
601+
// the unfiltered index instead.
602+
doc._url = window.location.pathname + window.location.search;
594603
}
595604
596605
const qs = {
@@ -747,7 +756,27 @@ export default {
747756
const normalizedUrl = url.replace(/^https?:\/\/[^/]+\//, '/');
748757
const currentPageUrl = window.location.pathname + window.location.search;
749758
750-
return normalizedUrl !== currentPageUrl;
759+
if (normalizedUrl === currentPageUrl) {
760+
return false;
761+
}
762+
763+
// The context doc's canonical URL may be a path prefix of the
764+
// current page's path (e.g. context doc is `/blog` and we're
765+
// viewing a piecesFilters path like `/blog/categories/events`,
766+
// generated when the piece-index module is configured with
767+
// `static: true`). That's not a slug change, just additional path
768+
// segments appended by the page itself, so don't treat it as a
769+
// difference requiring reconciliation. We don't require matching
770+
// the entire path, just the segment boundary, and we exclude the
771+
// root path ("/") from this check since virtually every path is
772+
// "under" it.
773+
const normalizedPath = normalizedUrl.split('?')[0];
774+
const currentPath = window.location.pathname;
775+
if (normalizedPath !== '/' && currentPath.startsWith(`${normalizedPath}/`)) {
776+
return false;
777+
}
778+
779+
return true;
751780
},
752781
lockNotAvailable() {
753782
if (this.contextStack.length) {

0 commit comments

Comments
 (0)