DEV Community

Discussion on: A simple way to keep your Vue page title in sync with the router

Collapse
 
imalexlab profile image
Alex Lab

Hello, here is a version with the composition API:

<script lang="ts">
import { defineComponent, watch } from 'vue';
import { useRoute } from 'vue-router';

export default defineComponent({
  setup() {
    const route = useRoute();

    watch(
      () => route.meta.title,
      () => {
        document.title = route.meta.title as string;
      }
    );
  },
});
</script>
Enter fullscreen mode Exit fullscreen mode