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

feat(link): expose useLink on RouterLink as internal #1002

Merged
merged 2 commits into from Jun 18, 2021

Conversation

KaelWD
Copy link
Contributor

@KaelWD KaelWD commented Jun 16, 2021

This allows us to make vue-router optional while still being able to use the composable instead of router-link itself:

import { resolveDynamicComponent } from 'vue'
import type {
  RouterLink as _RouterLink,
  useLink as _useLink,
  UseLinkOptions,
} from 'vue-router'

function useLink (props: Partial<UseLinkOptions>): ReturnType<typeof _useLink> | undefined {
  const RouterLink = resolveDynamicComponent('RouterLink') as typeof _RouterLink | string

  if (typeof RouterLink === 'string') return

  const link = RouterLink.useLink(props as UseLinkOptions)

  return props.to
    ? link
    : undefined
}

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@posva posva changed the title feat: expose useLink on the RouterLink constructor feat(link): expose useLink on RouterLink as internal Jun 18, 2021
@posva posva merged commit 57b1468 into vuejs:master Jun 18, 2021
@KaelWD KaelWD deleted the feat/useLink branch June 18, 2021 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants