[Vuejs]-The page loads twice in vue

0πŸ‘

  1. I don’t think "loading" is correct word here. Code needed for component is loaded from server only once as you can check in Dev Tools Network tab
  2. When switching routes, component for old route is destroyed and component for new route is created. Its default behavior of Vue dynamic component (it is what <router-view> uses for switching components). You can change that by using <keep-alive>. Be sure to check documentation and understand implications – your app will use more memory
  <keep-alive>
    <router-view :key="$route.fullPath"></router-view>
  </keep-alive>

Leave a comment