Actualizar sigpro.ts
This commit is contained in:
25
sigpro.ts
25
sigpro.ts
@@ -407,7 +407,6 @@ export function Tag(tag: string, props: any = {}, children: any = []): HTMLEleme
|
||||
return el;
|
||||
}
|
||||
|
||||
// Componente If con soporte de transiciones
|
||||
export function If(
|
||||
condition: (() => boolean) | boolean,
|
||||
thenVal: any,
|
||||
@@ -448,7 +447,6 @@ export function If(
|
||||
return container;
|
||||
}
|
||||
|
||||
// Componente For con keyed rendering
|
||||
export function For<T>(
|
||||
source: (() => T[]) | T[],
|
||||
renderFn: (item: T, index: number) => any,
|
||||
@@ -498,17 +496,12 @@ export function For<T>(
|
||||
return container;
|
||||
}
|
||||
|
||||
// Router con soporte mejorado
|
||||
export const Router = {
|
||||
params: $({} as Record<string, string>),
|
||||
to: (path: string) => { window.location.hash = path.replace(/^#?\/?/, "#/"); },
|
||||
back: () => window.history.back(),
|
||||
path: () => window.location.hash.replace(/^#/, "") || "/",
|
||||
outlet: (routes: Array<{ path: string; component: Component }>) => {
|
||||
export const Router = Object.assign(
|
||||
(routes) => {
|
||||
const currentPath = $(Router.path());
|
||||
window.addEventListener("hashchange", () => currentPath(Router.path()));
|
||||
const outlet = Tag("div", { class: "router-outlet" });
|
||||
let currentView: Runtime | null = null;
|
||||
let currentView = null;
|
||||
|
||||
Watch(currentPath, async () => {
|
||||
const path = currentPath();
|
||||
@@ -521,9 +514,9 @@ export const Router = {
|
||||
if (route) {
|
||||
let comp = route.component;
|
||||
if (isFunc(comp) && comp.toString().includes('import')) {
|
||||
comp = (await (comp as any)()).default || (await (comp as any)());
|
||||
comp = (await comp()).default || (await comp());
|
||||
}
|
||||
const params: Record<string, string> = {};
|
||||
const params = {};
|
||||
route.path.split("/").filter(Boolean).forEach((part, i) => {
|
||||
if (part.startsWith(":")) params[part.slice(1)] = path.split("/").filter(Boolean)[i];
|
||||
});
|
||||
@@ -535,7 +528,13 @@ export const Router = {
|
||||
});
|
||||
return outlet;
|
||||
},
|
||||
};
|
||||
{
|
||||
params: $({}),
|
||||
to: (path) => { window.location.hash = path.replace(/^#?\/?/, "#/"); },
|
||||
back: () => window.history.back(),
|
||||
path: () => window.location.hash.replace(/^#/, "") || "/",
|
||||
}
|
||||
);
|
||||
|
||||
export function Mount(component: Component | (() => any), target: string | HTMLElement): Runtime | undefined {
|
||||
const targetEl = typeof target === "string" ? doc.querySelector(target) : target;
|
||||
|
||||
Reference in New Issue
Block a user