vue3.0之如何获取当前路由地址


三种方式

import { defineComponent, ref, reactive, watch, toRaw, getCurrentInstance } from 'vue';

 

const { proxy }: any = getCurrentInstance();
    console.log(proxy.$router.currentRoute.value);
    const router = useRouter();
    console.log(router.currentRoute.value);
    watch(
      () => router,
      (newValue, oldValue) => {
        console.log(newValue.currentRoute.value, '新的路由');
        console.log(newValue.currentRoute.value, '旧的路由');
      },
      { immediate: true }
    );

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM