From a0bebd41e5ab14bcfa7428ae48996c4b28da797a Mon Sep 17 00:00:00 2001 From: natxocc Date: Wed, 8 Apr 2026 01:25:35 +0200 Subject: [PATCH] add Router --- sigwork_original.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sigwork_original.js b/sigwork_original.js index 2aba5b3..82c2499 100644 --- a/sigwork_original.js +++ b/sigwork_original.js @@ -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] }) => {