import PhotoShow from '../pages/photo/show.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/photo/show/:id',
props: true,
name: 'PhotoShow',
component: PhotoShow,
meta: { title: '图片浏览' }
}
]
const router = new VueRouter({
routes,
linkActiveClass: 'mui-active'
})
router.beforeEach((to, from, next) => {
if (to.meta.title) {
document.title = to.meta.title
}
next()
})
export default router
vue-router中router写法案例
最新推荐文章于 2024-11-18 23:59:29 发布
本文展示了如何使用 Vue Router 创建一个动态路由 `/photo/show/:id`,并实现在进入路由前更新页面标题的功能。通过 `props: true` 将参数传递给组件,同时定义了 `meta` 信息用于设置页面标题。`router.beforeEach` 用于在每次路由切换时更新 `document.title`,确保页面标题与当前路由对应。
2555

被折叠的 条评论
为什么被折叠?



