RouterLink
Introduction
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 Definitions
RouterLinkType
- Type Definition:
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 overlay
RouterLinkProps
- Type Definition:
Link configuration properties:
to: Target route location (string orRouteLocationobject)type: Navigation type (default:'push')replace: Deprecated — Usetype='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 whentype='pushLayer'beforeNavigate: Hook called before navigation; callevent.preventDefault()to block navigation
RouterLinkResolved
- Type Definition:
Resolved link data:
route: Resolved Route object for the target locationtype: Resolved navigation typeisActive: Whether the link matches the current route (based onexactstrategy)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 handlers
RouterLinkAttributes
- Type Definition:
HTML attributes generated for the link element:
href: Full href URLclass: CSS classes includingrouter-link,router-link-active, androuter-link-exact-activetarget: Set to'_blank'forpushWindowtype linksrel: Set to'noopener noreferrer'for new window links,'external nofollow'for external links
Methods
router.resolveLink()
- Parameters:
props: RouterLinkProps— Link configuration
- Returns:
RouterLinkResolved
Resolves link properties into complete link data. This is the primary method for building navigation links in any framework.
CSS Classes
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 onexactstrategy)router-link-exact-active: Applied when the link exactly matches the current route path
Usage Examples
Vue Usage
With @esmx/router-vue, use the RouterLink component:
React Manual Usage
In React, use router.resolveLink() to build link components: