The @esmx/router package provides a framework-agnostic link resolution system via router.resolveLink(). This method generates all necessary data for creating navigation links, including HTML attributes, active state detection, and event handlers.
type RouterLinkType =
| 'push'
| 'replace'
| 'pushWindow'
| 'replaceWindow'
| 'pushLayer';Navigation types for links:
push: Standard forward navigation (adds history entry)replace: Replaces current history entrypushWindow: Opens in a new browser windowreplaceWindow: Replaces current window locationpushLayer: Opens as a layer overlayinterface RouterLinkProps {
to: RouteLocationInput;
type?: RouterLinkType;
replace?: boolean;
exact?: RouteMatchType;
activeClass?: string;
event?: string | string[];
tag?: string;
layerOptions?: RouteLayerOptions;
beforeNavigate?: (event: Event, eventName: string) => void;
}Link configuration properties:
to: Target route location (string or RouteLocation object)type: Navigation type (default: 'push')replace: Deprecated — Use type='replace' insteadexact: Active state matching strategy ('include' | 'exact' | 'route')activeClass: Custom CSS class for active stateevent: Event(s) that trigger navigation (default: 'click')tag: HTML tag to render (default: 'a')layerOptions: Layer configuration when type='pushLayer'beforeNavigate: Hook called before navigation; call event.preventDefault() to block navigationinterface RouterLinkResolved {
route: Route;
type: RouterLinkType;
isActive: boolean;
isExactActive: boolean;
isExternal: boolean;
tag: string;
attributes: RouterLinkAttributes;
navigate: (e: Event) => Promise<void>;
createEventHandlers: (
format?: (eventType: string) => string
) => Record<string, (e: Event) => Promise<void>>;
}Resolved link data:
route: Resolved Route object for the target locationtype: Resolved navigation typeisActive: Whether the link matches the current route (based on exact strategy)isExactActive: Whether the link exactly matches the current route pathisExternal: Whether the link points to an external origintag: HTML tag to renderattributes: HTML attributes object (href, class, target, rel)navigate: Navigation handler function (respects modifier keys, prevents default appropriately)createEventHandlers: Factory for creating framework-specific event handlersinterface RouterLinkAttributes {
href: string;
class: string;
target?: '_blank';
rel?: string;
}HTML attributes generated for the link element:
href: Full href URLclass: CSS classes including router-link, router-link-active, and router-link-exact-activetarget: Set to '_blank' for pushWindow type linksrel: Set to 'noopener noreferrer' for new window links, 'external nofollow' for external linksprops: RouterLinkProps — Link configurationRouterLinkResolvedResolves link properties into complete link data. This is the primary method for building navigation links in any framework.
const linkData = router.resolveLink({
to: '/user/123',
type: 'push',
exact: 'include',
activeClass: 'nav-active'
});Links automatically receive CSS classes based on the current route:
router-link: Always applied to all router linksrouter-link-active: Applied when the link matches the current route (based on exact strategy)router-link-exact-active: Applied when the link exactly matches the current route pathWith @esmx/router-vue, use the RouterLink component:
<template>
<nav>
<RouterLink to="/home">Home</RouterLink>
<RouterLink to="/about" active-class="nav-active">About</RouterLink>
<RouterLink :to="{ path: '/user', query: { id: '1' } }">User</RouterLink>
<RouterLink to="/settings" type="replace">Settings</RouterLink>
</nav>
</template>In React, use router.resolveLink() to build link components:
function NavLink({ to, children }: { to: string; children: React.ReactNode }) {
const linkData = router.resolveLink({ to, type: 'push' });
const handlers = linkData.createEventHandlers(
(name) => `on${name.charAt(0).toUpperCase()}${name.slice(1)}`
);
return (
<a {...linkData.attributes} {...handlers}>
{children}
</a>
);
}const linkData = router.resolveLink({
to: '/dashboard',
event: ['click', 'touchstart'],
beforeNavigate: (event, eventName) => {
// Track analytics before navigation
analytics.track('nav_click', { target: '/dashboard' });
}
});
// Generate event handlers with custom naming
const handlers = linkData.createEventHandlers((type) => `on${type}`);const layerLink = router.resolveLink({
to: '/select-item',
type: 'pushLayer',
layerOptions: {
autoPush: true,
keepAlive: 'exact'
}
});