Skip to content

Link() function

Home > @rimitive/router > Link

Link builder function

Link is inherently DOM-coupled (uses window.history, MouseEvent, href, onclick). Routers are web browser concepts - no need for adapter abstraction here.

Signature:

export declare function Link(props: ElementProps<DOMAdapterConfig, 'a'> & {
href: string;
}): (...children: ElRefSpecChild[]) => RefSpec<HTMLAnchorElement>;

Parameter

Type

Description

props

ElementProps<DOMAdapterConfig, ‘a’> & { href: string; }

Returns:

(…children: ElRefSpecChild[]) => RefSpec<HTMLAnchorElement>

import { Link } from '@rimitive/router';
// Basic link
const navLink = Link({ href: '/about' })('About Us');
// Link with props
const styledLink = Link({
href: '/products',
class: 'nav-link',
onclick: (e) => console.log('clicked')
})('Products');
// Dynamic navigation
const productId = signal('123');
const dynamicLink = Link({
href: computed(() => `/products/${productId()}`)
})('View Product');