I have a problem with Nuxt 3. Here is the code:
<NuxtLink
:to="{
path: '/',
query: useRoute().query,
}">Link</NuxtLink>
How to use this code without writing query, like the code below, but without losing parameters? If I'm not writing query, it's making the URL query parameters empty but redirecting to needed page:
<NuxtLink to="/">Link</NuxtLink>
Thank you!
You can try a custom function to unify your
toobject. This gives you some degree of flexibility in the template in case you need to manipulate thetoobjectAlternatively, if you want a more global override, you can create a global route middleware that adds a query from the current route object to the next one, if no query is found. You can then use
<NuxtLink>as usualhttps://nuxt.com/docs/migration/plugins-and-middleware#route-middleware https://nuxt.com/docs/guide/directory-structure/middleware