6

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>
kissu
  • 40,416
  • 14
  • 65
  • 133

2 Answers2

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

sadeq shahmoradi
  • 1,395
  • 1
  • 6
  • 22
  • 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`. – kissu Aug 21 '23 at 13:43
-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("/");
kissu
  • 40,416
  • 14
  • 65
  • 133
  • 7
    Nope, please DO NOT use this because you will nuke your SPA. There is no point into doing that. Totally counter-productive. – kissu Mar 29 '22 at 09:53
  • 1
    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](/help/how-to-answer). – Community Mar 30 '22 at 02:40