-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed as not planned
Description
What problem is this solving
I am writing a component that wraps RouterLink
, but I would like to use the useLink
composable to easily access refs like isActive
in the setup function.
In order to use both useLink
and RouterLink
in a single component, a new RouterLink
prop could be introduced so that useLink
's returned value may be provided instead of the to
prop. The implementation can be easily achieved; the main concern would be updating RouterLinkProps
type. An union could be used to define RouterLinkProps
so that either to
or the new prop are provided.
Apart from simplified link's consumption/access, I think another secondary benefit would be that if RouterLink
gets unmounted (e.g., with v-if
), useLink
does not have to be called on every mount.
Proposed solution
<script setup>
const link = useLink()
// ... use link during setup
</script>
<template>
<!-- Provide link implementation -->
<RouterLink :link>
</RouterLink>
</template>
Describe alternatives you've considered
- Use
useLink
only: Requires rewriting part ofRouterLink
. - Use
RouterLink
only: Requires extracting its slot props from the template for use in the setup function, which is somewhat cumbersome, and they become available until the mounting phase. - Use both independently: Would create two different sets of computed values and functions that do the same, one for the setup function, and one for the
RouterLink
component.
Metadata
Metadata
Assignees
Labels
No labels