abnormalize0 / DailyTeleFrog

0 stars 0 forks source link

Vue Guards #134

Open serynabatov opened 4 months ago

serynabatov commented 4 months ago

The previous functionality

<script setup>
  import { watch, ref } from "vue";
  import { useRoute } from "vue-router";

  const login = ref(false);
  const route = useRoute();
  watch(
    () => route.fullPath,
    async () => {
      console.log("changed");
      console.log(localStorage.id);
      if ((localStorage.getItem("id") === null)  (localStorage.id == 0)) {
        localStorage.id = 0;
        login.value = 0;
      } else {
        login.value = 1;
      }
    }
  );

  if ((localStorage.getItem("id") === null)  (localStorage.id == 0)) {
    localStorage.id = 0;
  } else {
    login.value = 1;
  }
</script>

It should be migrated to https://router.vuejs.org/guide/advanced/navigation-guards.html