Skip to content

useIsView

Returns a reactive boolean that tracks whether the current route matches a given record name. Built on top of useRouteNames.

Importing

ts
import { useIsView } from '@basmilius/routing';

Signature

ts
declare function useIsView(name: string, loose?: boolean): ComputedRef<boolean>;
ArgumentTypeDescription
namestringRoute record name to test against.
loosebooleanOptional, defaults to false. When true, the test is startsWith instead of strict equality on names.

Usage

vue
<script
    setup
    lang="ts">
    import { useIsView } from '@basmilius/routing';

    const isUser = useIsView('user');
    const isUserSection = useIsView('user.', true);
</script>

<template>
    <nav :class="{ 'nav--user': isUser }">...</nav>
</template>

useIsView('user') matches a route whose matched chain contains a record literally named user. useIsView('user.', true) matches every nested record (user.profile, user.settings).

Notes

  • The composable consumes useRouteNames under the hood, so it sees the same route as useRoute — including the route override applied inside background or modal subtrees.
  • Records without a name are skipped by useRouteNames, so they cannot be matched here.

See also