路由信息
<div>route {{ $route.fullPath }}</div>
import { useRoute } from 'vue-router' const route = useRoute()
<div>route {{ route.fullPath }}</div>
console.log(route)
分类 | 说明 |
---|---|
name | 匹配的路由名称
Name of the matched record |
path | 经过百分号编码的 URL 中的 pathname 段
Percentage encoded pathname section of the URL. |
params | 动态路由信息;从 path 中提取出来并解码后的参数对象
Object of decoded params extracted from the path. |
query | 查询路由信息;代表当前地址的 search 属性的对象
Object representation of the search property of the current location. |
matched | 匹配路由;数组,只包含直接的组件 (任何已被加载并在 components 对象内被替换掉的懒加载组件) 可以被直接用于展示路由。不包含重定向记录 |
<div>params: {{ $route.params.id }}</div>
onMounted(() => { console.log(route.params.id) // fetch() // axios() })
const share = () => { router.push({ query: { id: 100, user: 'xinhua' } }) }
onMounted(() => { const id = route.query.id || 999 // axios.get(`/api/todo/${id}`).then(res => {}) })
{ path: "/login-guide", name: "login-guide", component: () => import("../views/LoginGuide.vue"), meta: { title:"注册与登录", showNav: false, requiresAuth: false, }, }
onMounted(() => { document.title = route.meta.title })
<AppNav v-if="!$route.meta.showNav" />
<div class="bread"> <div v-for="(item, index) in $route.matched" :key="index">{{ item.name }}/</div> </div>