vue3 + vite 监听路由
1. watch监听
import { watch} from 'vue'
import {useRouter} from 'vue-router'
let router = useRouter()
watch(() =>router.currentRoute._value,(m,n)=> {
console.log('watch',m)
},{ immediate: true })
2. onBeforeRouteUpdate 导航守卫
// f5 刷新不触发
import { onBeforeRouteUpdate } from 'vue-router'
onBeforeRouteUpdate((to) => {
console.log('to',to)
});