slicejs-web-framework 1.0.26 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -203,50 +203,54 @@ export default class Router {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
async handleRoute(route, params) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
const targetElement = document.querySelector('#app');
|
|
207
|
+
|
|
208
|
+
const componentName = route.parentRoute ? route.parentRoute.component : route.component;
|
|
209
|
+
const sliceId = `route-${componentName}`;
|
|
210
|
+
|
|
211
|
+
const existingComponent = slice.controller.getComponent(sliceId);
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
if (slice.loading) {
|
|
214
|
+
slice.loading.start();
|
|
215
|
+
}
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
targetElement.appendChild(existingComponent);
|
|
224
|
-
} else {
|
|
225
|
-
const component = await slice.build(componentName, {
|
|
226
|
-
params,
|
|
227
|
-
sliceId: sliceId,
|
|
228
|
-
});
|
|
229
|
-
targetElement.innerHTML = '';
|
|
230
|
-
targetElement.appendChild(component);
|
|
217
|
+
if (existingComponent) {
|
|
218
|
+
targetElement.innerHTML = '';
|
|
219
|
+
if (existingComponent.update) {
|
|
220
|
+
existingComponent.props = { ...existingComponent.props, ...params };
|
|
221
|
+
await existingComponent.update();
|
|
231
222
|
}
|
|
223
|
+
targetElement.appendChild(existingComponent);
|
|
224
|
+
// Renderizar DESPUÉS de insertar (pero antes de mostrar)
|
|
225
|
+
await this.renderRoutesInComponent(existingComponent);
|
|
226
|
+
} else {
|
|
227
|
+
const component = await slice.build(componentName, {
|
|
228
|
+
params,
|
|
229
|
+
sliceId: sliceId,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
targetElement.innerHTML = '';
|
|
233
|
+
targetElement.appendChild(component);
|
|
234
|
+
|
|
235
|
+
// Renderizar INMEDIATAMENTE después de insertar
|
|
236
|
+
await this.renderRoutesInComponent(component);
|
|
237
|
+
}
|
|
232
238
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
await this.renderRoutesComponentsInPage();
|
|
236
|
-
|
|
237
|
-
if (slice.loading) {
|
|
238
|
-
slice.loading.stop();
|
|
239
|
-
}
|
|
239
|
+
// Invalidar caché después de cambios importantes en el DOM
|
|
240
|
+
this.invalidateCache();
|
|
240
241
|
|
|
241
|
-
|
|
242
|
+
if (slice.loading) {
|
|
243
|
+
slice.loading.stop();
|
|
242
244
|
}
|
|
243
245
|
|
|
246
|
+
slice.router.activeRoute = route;
|
|
247
|
+
}
|
|
248
|
+
|
|
244
249
|
async loadInitialRoute() {
|
|
245
250
|
const path = window.location.pathname;
|
|
246
251
|
const { route, params } = this.matchRoute(path);
|
|
247
252
|
|
|
248
253
|
await this.handleRoute(route, params);
|
|
249
|
-
await this.renderRoutesComponentsInPage();
|
|
250
254
|
}
|
|
251
255
|
|
|
252
256
|
matchRoute(path) {
|