vue-router中需要注意的事项

动态匹配:/xxxx/:id 这样匹配路由时后面必须跟参数否则404
命名:name: ‘xxx’ 可用name跳转
重定向:redirect: ‘/xxx’ 此处跟的是path
使用params传参只能用name来引入路由

路由组件传参
props可将动态匹配参数分离
布尔模式:props: true 在组件内props: [‘id’](成为了组件的属性)可直接用id获取该参数
对象模式:props: { xxxx: ‘xxx’ } 直接作为组件的属性来使用
函数模式:props: route => ({ id: route.query.id,name: ‘xxx’ })同样作为属性
元信息:meta: {} 可在this.$route.meta中拿到

this.$route同router.beforeEach(路由守卫)的to

切换路由回滚顶部

new VueRouter({
    
    routes:[],scrollBehavior (to, from, savedPosition) {
    
    
	return {
    
     x: 0, y: 0 }
}})

懒加载:() => import(’@/xxx/xxx’)

keep-alive中的name是组件中的name不是router里面的

猜你喜欢

转载自blog.csdn.net/weixin_45685252/article/details/124244071