Getting Started with Router
Prerequisites
Before continuing, make sure you're familiar with: SignalX Core basics, Components
The SignalX Router provides declarative, type-safe routing for your SignalX applications with full SSR support.
Installation
pnpm add @sigx/router
Basic Setup
Create a router instance and define your routes:
import { createRouter, RouterView, RouterLink } from '@sigx/router';
import { createApp } from 'sigx';
// Define your routes
const router = createRouter({
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About },
{ path: '/users/:id', component: UserProfile },
],
});
// Create your app with the router plugin
const app = createApp(App);
app.use(router);
app.mount('#app');
Using RouterView
The RouterView component renders the matched route component:
import { component } from 'sigx';
import { RouterView, RouterLink } from '@sigx/router';
const App = component(() => {
return () => (
<div>
<nav>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/about">About</RouterLink>
</nav>
<main>
<RouterView />
</main>
</div>
);
});
RouterLink Component
Use RouterLink for navigation instead of regular anchor tags:
<RouterLink to="/users/123">View User</RouterLink>
{/* With active class */}
<RouterLink
to="/about"
activeClass="text-primary font-bold"
>
About
</RouterLink>
Next Steps
- Defining Routes - Learn about route configuration
- Navigation - Programmatic navigation
- Route Guards - Protect routes with guards
- SSR Routing - Server-side rendering and hash-based routing for static hosts