task-7(壳层/路由): 根路由跳转到首个可见页面,移除硬编码默认页
helpers.firstVisiblePath 深度优先返回首个可路由页面,无页面返回空串; store 增加 firstVisible;守卫在根路由/无权限时跳首个可见页,全部无页面则 停留根路由展示无菜单空态,删除 redirect:'/account/users' 硬编码。
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import type { AdminMenuNode } from '../types/admin'
|
||||
|
||||
/**
|
||||
* 取后端菜单树中第一个可路由页面路径(深度优先、保序)。
|
||||
* 无任何可路由页面时返回空串,由调用方决定渲染空态或回根路由,不硬编码缺省页。
|
||||
*/
|
||||
export function firstVisiblePath(nodes: AdminMenuNode[] | null | undefined): string {
|
||||
for (const node of nodes || []) {
|
||||
if (node.route) return node.route
|
||||
const nested = firstVisiblePath(node.children || [])
|
||||
if (nested) return nested
|
||||
}
|
||||
return ''
|
||||
}
|
||||
Reference in New Issue
Block a user