diff --git a/src/core/drive/page_snapshot.js b/src/core/drive/page_snapshot.js index 58a5a75a9..620aacf86 100644 --- a/src/core/drive/page_snapshot.js +++ b/src/core/drive/page_snapshot.js @@ -82,6 +82,10 @@ export class PageSnapshot extends Snapshot { return this.getSetting("refresh-scroll") === "preserve" } + get morphURLPrefix() { + return this.getSetting("morph-url-prefix") ?? "" + } + // Private getSetting(name) { diff --git a/src/core/drive/page_view.js b/src/core/drive/page_view.js index 1583f25a0..5d80cce0f 100644 --- a/src/core/drive/page_view.js +++ b/src/core/drive/page_view.js @@ -16,8 +16,7 @@ export class PageView extends View { } renderPage(snapshot, isPreview = false, willRender = true, visit) { - const shouldMorphPage = this.isPageRefresh(visit) && this.snapshot.shouldMorphPage - const rendererClass = shouldMorphPage ? MorphRenderer : PageRenderer + const rendererClass = this.shouldMorphPage(visit) ? MorphRenderer : PageRenderer const renderer = new rendererClass(this.snapshot, snapshot, PageRenderer.renderElement, isPreview, willRender) @@ -63,6 +62,18 @@ export class PageView extends View { return this.isPageRefresh(visit) && this.snapshot.shouldPreserveScrollPosition } + shouldMorphPage(visit) { + return (this.isPageRefresh(visit) || this.isMorphableURL(visit)) && this.snapshot.shouldMorphPage + } + + isMorphableURL(visit) { + return ( + this.snapshot.morphURLPrefix != "" && + this.lastRenderedLocation.pathname.startsWith(this.snapshot.morphURLPrefix) && + visit.action === "advance" + ) + } + get snapshot() { return PageSnapshot.fromElement(this.element) }