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

Warning will appear when passing an external link to <NuxtLink> #27312

Closed
Mini-ghost opened this issue May 22, 2024 · 3 comments · Fixed by #27487
Closed

Warning will appear when passing an external link to <NuxtLink> #27312

Mini-ghost opened this issue May 22, 2024 · 3 comments · Fixed by #27487

Comments

@Mini-ghost
Copy link
Contributor

Mini-ghost commented May 22, 2024

Environment


  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.12.0-28606556.69430aa2
  • CLI Version: 3.11.2-1716385490.bfaf128
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-jphpju?file=app.vue

Describe the bug

  1. Start Reproduction. It includes the following code:
    <NuxtLink to="https://nuxt.com/">Nuxt</NuxtLink>
  2. Open the Console panel in DevTools.
  3. A warning appears: [Vue Router warn]: No match found for location with path "https://nuxt.com/".
截圖 2024-05-23 凌晨1 29 32

Additional context

This might be related to this PR: #26522.

Logs

N/A

Copy link

stackblitz bot commented May 22, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@Mini-ghost
Copy link
Contributor Author

Mini-ghost commented May 22, 2024

I've tested various scenarios regarding this PR #26522 and noticed that the useLink from this PR behaves slightly differently from Vue Router's useLink. For example:

<script setup lang="ts">
import { useLink } from 'vue-router'

const props = shallowReactive({
  to: 'https://mini-ghost.dev',
})

const { isActive } = useLink(props)
const { isActive: isNuxtLinkActive } = resolveComponent('NuxtLink').useLink(props)

const onClick = () => {
  if (props.to === '/') {
    props.to = '/about'
  } else {
    props.to = '/'
  }
}
</script>

<template>
  <div>
    <button @click="onClick">
      Click
    </button>

    isActive {{ isActive }} <br>
    isNuxtLinkActive: {{ isNuxtLinkActive }}
  </div>
</template>

When we switch routes by clicking the <button>, Vue Router's isActive reacts to the changes, but <NuxtLink>'s isNuxtLinkActive does not respond to changes in data. This issue might be caused by the following code segment:

const link = useBuiltinLink?.({
...props,
to: to.value,
})

Here, we are destructuring the passed props, which if reactive or shallowReactive, would lose their reactivity.

Should we align <NuxtLink>'s useLink behavior with Vue Router's useLink?

@danielroe
Copy link
Member

Nice find! Yes, we should ensure this remains reactive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants