mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-10-27 01:32:10 +08:00 
			
		
		
		
	fix(TabBar): route matching in special cases (#10447)
This commit is contained in:
		
							parent
							
								
									cda29f68fe
								
							
						
					
					
						commit
						daaaa84945
					
				| @ -32,19 +32,22 @@ export default createComponent({ | ||||
|   }, | ||||
| 
 | ||||
|   computed: { | ||||
|     routeMatched() { | ||||
|       const { to, $route } = this; | ||||
|       if (to && $route) { | ||||
|     active() { | ||||
|       const routeMode = this.parent.route; | ||||
| 
 | ||||
|       if (routeMode && '$route' in this) { | ||||
|         const { to, $route } = this; | ||||
|         const config = isObject(to) ? to : { path: to }; | ||||
|         return !!$route.matched.find(r =>{ | ||||
|           const pathMatched = config.path === r.path; | ||||
|         return !!$route.matched.find((r) => { | ||||
|           // vue-router 3.x $route.matched[0].path is empty in / and its children paths
 | ||||
|           const path = r.path === '' ? '/' : r.path; | ||||
|           const pathMatched = config.path === path; | ||||
|           const nameMatched = isDef(config.name) && config.name === r.name; | ||||
|           return pathMatched || nameMatched; | ||||
|         }) | ||||
|         }); | ||||
|       } | ||||
|     }, | ||||
|     active() { | ||||
|       return this.parent.route ? this.routeMatched : this.nameMatched; | ||||
| 
 | ||||
|       return this.nameMatched; | ||||
|     }, | ||||
|   }, | ||||
| 
 | ||||
|  | ||||
| @ -69,7 +69,7 @@ export default createComponent({ | ||||
|   methods: { | ||||
|     setActiveItem() { | ||||
|       this.children.forEach((item, index) => { | ||||
|         item.nameMatched = (item.name || index) === this.value; | ||||
|         item.nameMatched = item.name === this.value || index === this.value; | ||||
|       }); | ||||
|     }, | ||||
| 
 | ||||
|  | ||||
| @ -10,7 +10,7 @@ exports[`placeholder prop 1`] = ` | ||||
| 
 | ||||
| exports[`route mode 1`] = ` | ||||
| <div class="van-hairline--top-bottom van-tabbar van-tabbar--fixed"> | ||||
|   <div class="van-tabbar-item"> | ||||
|   <div class="van-tabbar-item van-tabbar-item--active"> | ||||
|     <div class="van-tabbar-item__icon"> | ||||
|       <!----> | ||||
|     </div> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user