方式
场景,在代码中主动跳转到另一个路由。
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();//拿到路由器 注意不是路由useRoute
onMounted(()=>{
setTimeout(()=>{
console.log('@')
router.push('/pm') //主动跳转
},2000)
})
</script>
重定向
在路由器中配置规则
{
path:'/',
redirect:'/home'主界面重定向到/home路由对应的规则
}