import{_ as i,o as a,c as t,ae as n}from"./chunks/framework.C8AWLET_.js";const E=JSON.parse('{"title":"Navigation Plugin: Router","description":"","frontmatter":{},"headers":[],"relativePath":"plugins/core.router.md","filePath":"plugins/core.router.md"}'),e={name:"plugins/core.router.md"};function h(l,s,p,k,r,d){return a(),t("div",null,[...s[0]||(s[0]=[n(`
Router The SigPro Router handles URL changes via hashes (#) and maps them to components. It supports dynamic parameters (like :id) and asynchronous loading for heavy pages.
/user/:id.The Router is usually included in the official plugins package.
npm install -D tailwindcss @tailwindcss/vite daisyui@nextpnpm add -D tailwindcss @tailwindcss/vite daisyui@nextyarn add -D tailwindcss @tailwindcss/vite daisyui@nextbun add -d tailwindcss @tailwindcss/vite daisyui@nextIn your App.js (or a dedicated routes file), define your navigation map.
const routes = [
{ path: '/', component: () => h1("Home Page") },
{
path: '/admin',
// Lazy Loading: This file is only fetched when needed
component: () => import('./pages/Admin.js')
},
{ path: '/user/:id', component: (params) => h2(\`User ID: \${params.id}\`) },
{ path: '*', component: () => div("404 - Page Not Found") }
];
export default () => div([
_navbar({ title: "My App" }),
_router(routes) // The router is now a global tag
]);_router.go) To move between pages programmatically (e.g., inside an onclick event), use the global _router.go helper.
_button({
onclick: () => _router.go('/admin')
}, "Go to Admin")The router tracks the window.location.hash and uses a reactive signal to trigger a re-render of the specific area where _router(routes) is placed.
import()), it shows a loading state and swaps the content once the module arrives.Since you are using the UI Plugin, you can easily create active states in your navigation menus by checking the current hash.
// Example of a reactive sidebar menu
_menu({
items: [
{
label: 'Dashboard',
active: () => window.location.hash === '#/',
onclick: () => _router.go('/')
},
{
label: 'Settings',
active: () => window.location.hash === '#/settings',
onclick: () => _router.go('/settings')
}
]
})