#Same URL via `navigateTo` cannot execute `useFetch`

3 messages · Page 1 of 1 (latest)

terse bronze
#

I redirect to same URL (not same query parameters) via navigateTo. However, it seems that useFetch wasn't executed.
On the other hands, useFetch is executed when redirect to different URL via navigateTo.
Is there a way to execute useFetch in the case of a redirect to the same URL?

Reproduction: https://github.com/mogi86/study-nuxt3-v2/blob/v0.0.4/src/pages/content.vue

  1. yarn install
  2. yarn dev
  3. access to http://localhost:3000/content/
    4-1. push Display this content button => cannot execute useFetch
    4-2. push Display other content button => can execute useFetch
GitHub

Contribute to mogi86/study-nuxt3-v2 development by creating an account on GitHub.

lilac flame
#

If you're okay with using another approach, I'd suggest leaving out navigateTo. Consider using the refresh() function on useFetch().

Here's an example

 const searchInput = ref("");
 
 const { data: questions, pending, refresh, error } = await useFetch<IQuestion[]>(() => `/api/ask-jack/search?search=${searchInput.value}`, {server:false})

 refresh()

 function search() {
     if (searchInput.value.length >= 3) {
         refresh()
     }
 }
 
#

The important parts to pay attention to there are that you can call search however you like and that will prompt the useFetch to re-run the query