Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button: Add route types to to prop (RouteLocation | RouteLocationRaw) #578

Closed
madebyfabian opened this issue Aug 27, 2023 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@madebyfabian
Copy link
Contributor

Is your feature request related to a problem? Please describe.

I am using Nuxt with the experimental.typedRoutes feature. When I use the button for creating a link, like this

<template>
  <UButton
    variant="link"
    :to="{ name: 'admin-content-jobs' }">
    Jobs
  </UButton>
</template>

The to prop is not defined as a prop in the types of the library (in the Button.vue.d.ts inside the node_modules folder).
So I don't get type checks and also no errors if I add a wrong route in there.

Describe the solution you'd like

Ideally, these two types (RouteLocation | RouteLocationRaw) would be added to the to prop by nuxthq/ui, so that the prop is typed.

Describe alternatives you've considered

What I can do is something like this:

<template>
  <UButton
    variant="link"
    :to="to">
    Jobs
  </UButton>
</template>

<script lang="ts" setup>
import type { RouteLocation, RouteLocationRaw } from '#vue-router'
const to: RouteLocation | RouteLocationRaw = { name: 'admin-content-jobs' }
// Or
const router = useRouter()
const to = router.resolve({ name: 'admin-content-jobs' })
</script>

Now the route object is typechecked and I can add it to the to field. Works, but not ideal.

@madebyfabian madebyfabian added the enhancement New feature or request label Aug 27, 2023
Copy link
Member

I'm aware of this, we should have a ...NuxtLink.props inside the Button props.

I've removed it as it breaks nuxt-component-meta for the docs as I didn't find a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants