Nuxt.js vuex store not persisted

Alright, so the behavior is totally logic. Vuex/Pinia are not supposed to be persistent.

For any persistence on the front-end, you need either:

  • cookies
  • localStorage
  • pass it in the URL (query params)
  • IndexedDB
  • get the data back from making a call to a backend

If you are using Vuex or Pinia, there are also packages that you could use to get an easier time (to sync your store into something persistent automatically).

Some of the packages here may be useful: https://github.com/vuejs/awesome-vue#persistence

For pinia: https://stackoverflow.com/a/73863929/8816585


If you reload your page with an F5, all your JS will be wiped and loaded again. Hence, no state will be kept since it will be a brand new page. When working with frontend frameworks, you cannot expect it to just work after a page refresh.

Same go when you do follow an href, it is an actual real navigation. What you need to do, is to use a <nuxt-link></nuxt-link> component, with something like to="/profile" to let VueJS move to this URL.

NuxtLink is a Nuxt.js component and essentially a component on top of <router-link></router-link>, which is Vue router.

TLDR: you cannot use things like window.location.href, nor <a href="...". You may use the given components by either Nuxt (nuxt-link) or Vue’s router (router-link), if you’re using VueJS only.

Giving a read to the Vue router’s documentation may be a good start to understand things a bit more !


If you’re using nuxt/auth, give a try to that one: https://auth.nuxtjs.org/api/storage/#universal-storage

Leave a Comment