应用最多;动态路由参数将被当作同名属性参数在组件中使用
{ path: '/home/:id/:title/:cont/:other?', name: "home", component: Home, props: true }
<router-link to="/home/10/webjs/hi">html</router-link>
<script> - 定义属性来接收路由参数
const props = defineProps(['id', 'title', 'cont'])
<template> - 使用|渲染路由参数
<div>{{id}} - {{title}} - {{cont}}</div>
{ path: '/home', name: "home", component: Home, props: route => route.query }
<router-link :to="{ path: '/home', query: { id: 100, title: 'leading', cont: 'hi' } }">home</router-link>
<script> - 定义属性来接收路由参数;要十分清楚使用了几个查询参数
const props = defineProps(['id', 'title', 'cont'])
<template> - 使用|渲染路由参数
<div>{{id}} - {{title}} - {{cont}}</div>
{ path: '/about/:id/:msg', name: 'about', component: () => import('../views/AboutView.vue'), props: route => ({ id: Number(route.params.id), msg: route.params.msg }) }
const props = defineProps({ id: Number, msg: String })
{ path: '/about/:id', name: 'about', component: () => import('../views/AboutView.vue'), props: { msg: { title: 'About', flag: true }, } }
const props = defineProps({ msg: { flag: Boolean, title: String } })