useRouter
Commons
stable
Thin wrappers around Vue Router that expose the current route and router instance from the Vue component instance rather than via direct vue-router import. Also provides useLink (a link-resolution helper used by all clickable Origam components) and useBackButton (navigation guard for hardware/browser back button interception).
API
Signature
Full TypeScript signature sourced from the composable file.
Consumed interfaces
ILinkProps
ITagProps
ILink
API
Parameters
Input parameters accepted by this composable.
- props (useLink)requiredILinkProps & ITagProps
- Props containing `href` (external link), `to` (vue-router location), `tag` (root element override), and `exact` (exact-active matching).
- attrs (useLink)requiredSetupContext['attrs']
- The component attrs used to detect a click listener, which makes a non-link element behave as clickable.
- router (useBackButton)requiredRouter | undefined
- The Router instance. When undefined (no vue-router), only the popstate listener is registered.
- cb (useBackButton)required(next: NavigationGuardNext) => void
- Guard callback called when a popstate (back) event is detected. Must call next() to allow navigation or next(false) to cancel.
API
Return values
Properties and methods exposed by the composable return object.
- tag (useLink)
- "a" when href or to is present, otherwise the tag prop or "div".
- isLink (useLink)
- True when props.href or props.to is set.
- isClickable (useLink)
- True when isLink or a click listener is present in props/attrs.
- isActive (useLink)
- True when the resolved route matches the current location (honours exact prop).
- href (useLink)
- The resolved href — either props.href (external) or the vue-router resolved route href.
- navigate (useLink)
- RouterLink.navigate function for programmatic navigation. Undefined when using a plain href.
Usage
Examples
Ready-to-paste usage snippets.
Read the current route
Origam button as router-link
Back button guard (Dialog)