Skip to content

Commit a1cf7eb

Browse files
committed
re-implemented shared route component
1 parent 140571c commit a1cf7eb

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/external/router-slot/router-slot.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,23 @@ export class RouterSlot<D = any, P = any> extends HTMLElement implements IRouter
409409
return cancel();
410410
}
411411

412-
// Remove the old page by clearing the slot
413-
this.clearChildren();
412+
// We have some routes that share the same component instance, those should not be removed and re-appended [NL]
413+
const isTheSameComponent = this.firstChild === page;
414+
415+
if(!isTheSameComponent) {
416+
// Remove the old page by clearing the slot
417+
this.clearChildren();
418+
}
414419

415420
// Store the new route match before we append the new page to the DOM.
416421
// We do this to ensure that we can find the match in the connectedCallback of the page.
417422
this._routeMatch = match;
418423

419-
if (page) {
420-
// Append the new page
421-
this.appendChild(page);
424+
if(!isTheSameComponent) {
425+
if (page) {
426+
// Append the new page
427+
this.appendChild(page);
428+
}
422429
}
423430
}
424431

src/packages/documents/documents/workspace/document-workspace-editor.element.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from './document-workspace.context-tok
1212
export class UmbDocumentWorkspaceEditorElement extends UmbLitElement {
1313
//
1414
// TODO: Refactor: when having a split view/variants context token, we can rename the split view/variants component to a generic and make this component generic as well. [NL]
15-
//private splitViewElement = new UmbDocumentWorkspaceSplitViewElement();
15+
private splitViewElement = new UmbDocumentWorkspaceSplitViewElement();
1616

1717
#appLanguage?: typeof UMB_APP_LANGUAGE_CONTEXT.TYPE;
1818
#workspaceContext?: typeof UMB_DOCUMENT_WORKSPACE_CONTEXT.TYPE;
@@ -67,7 +67,7 @@ export class UmbDocumentWorkspaceEditorElement extends UmbLitElement {
6767
routes.push({
6868
// TODO: When implementing Segments, be aware if using the unique still is URL Safe, cause its most likely not... [NL]
6969
path: variantA.unique + '_&_' + variantB.unique,
70-
component: UmbDocumentWorkspaceSplitViewElement,
70+
component: this.splitViewElement,
7171
setup: (_component, info) => {
7272
// Set split view/active info..
7373
const variantSplit = info.match.fragments.consumed.split('_&_');
@@ -84,7 +84,7 @@ export class UmbDocumentWorkspaceEditorElement extends UmbLitElement {
8484
routes.push({
8585
// TODO: When implementing Segments, be aware if using the unique still is URL Safe, cause its most likely not... [NL]
8686
path: variant.unique,
87-
component: UmbDocumentWorkspaceSplitViewElement,
87+
component: this.splitViewElement,
8888
setup: (_component, info) => {
8989
// cause we might come from a split-view, we need to reset index 1.
9090
this.#workspaceContext?.splitView.removeActiveVariant(1);

0 commit comments

Comments
 (0)