<NuxtLink> in Nuxt 3 only show the page's content after refreshing
Asked Answered
H

2

7

I am trying to use <NuxtLink> to redirect in Nuxt 3.

However, my page won't show after the URL change. That means, after clicking the link, the URL changes to whatever is stated in the to="", but the content doesn't show unless I refresh the page. Wonder what did I do wrong.

Here is my Routing code

 <template>
      <div class="top-nav-tab">
        <NuxtLink to="/foundations"><h3>Foundations</h3></NuxtLink>
     </div>
   </template>

Here is my page code

<template>
  <h2>Foundation page</h2>
</template>
Hoosegow answered 15/11, 2021 at 19:51 Comment(5)
Hi, could you please show us your routes? – Swaddle
there is nothing wrong with that code, are you sure you have all the dependencies up to date? – Dynameter
It's related to useAsyncData if you're using it in a lazy mode, something doesn't fetch from API correctly, thus it won't show anything – Gabar
I wonder if it is fixed? πŸ€” – Frogmouth
Check your console maybe you have error in your console. – Vestiary
P
0

Instead of using NuxtLink, Why not use another implementation like: navigateTo() as Nuxtlink creates a lazyloaded component by default? So in this use case just do something like

<h3 @click="navigateTo('/foundation')"> Foundation </h3>

This would perform the action; and its preferred way by the documentation

Perni answered 21/8, 2023 at 9:2 Comment(1)
Lazy loaded component? You rather mean prefetching no? Also, a11y semantics are important: a link should move you to a place, not a button or even an h3. – Swaddle
C
-5

I've got the same issue so I use native javascript instead.

// Simulate a mouse click:
window.location.href = "/";

// Simulate an HTTP redirect:
window.location.replace("/");
Captive answered 29/3, 2022 at 9:33 Comment(2)
Nope, please DO NOT use this because you will nuke your SPA. There is no point into doing that. Totally counter-productive. – Swaddle
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Anele

© 2022 - 2024 β€” McMap. All rights reserved.