add Router

This commit is contained in:
2026-04-08 01:25:35 +02:00
parent c1beda24ca
commit a0bebd41e5

View File

@@ -245,6 +245,15 @@ export const For = (list, key, renderFn) => {
}
}
export const Router = (routes) => {
const path = signal(window.location.hash.slice(1) || '/');
window.onhashchange = () => path.value = window.location.hash.slice(1) || '/';
return h('div', { class: 'router-view' }, () => {
const route = routes.find(r => r.path === path.value) || routes.find(r => r.path === '*');
return route ? h(route.component) : null;
});
};
export const Component = ({ is, ...props }, { children }) => () => h(isFn(is) ? is() : is, props, children);
export const Transition = ({ enter: e, idle, leave: l }, { children: [c] }) => {