Files
zMainPage/src/router/index.js
zikai 370388e729 fix: 白板页签乐观显示 + 白板切换输入框 + /whiteboard/{id} 直链
- 存活逻辑改为乐观显示:探测中(pending)/存活(up) 都显示页签,仅明确
  不可达(down) 才隐藏。修复首屏看不到页签、需刷新才出现的问题
- 白板页加 ID 输入框与切换按钮,可切换不同白板,默认 share
- 路由支持 /whiteboard/:boardId 可选参数,直链访问自动填入输入框并切换
- 模块可声明 param 让路由表生成子路径,保持注册表驱动
2026-07-22 02:43:26 +00:00

47 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 路由表由模块注册表动态生成 -- 新增模块自动产生路由,无需手改。
import { createRouter, createWebHistory } from 'vue-router'
import modules from '../modules/index.js'
const moduleRoutes = modules
.map((m) => {
try {
// 模块可声明 param如 'boardId')以接受 /<id>/<param> 形式的子路径,
// 形如 /whiteboard/share。可选参数 (? 后缀) 使 /whiteboard 仍可访问。
const paramPart = m.param ? `/:${m.param}?` : ''
return {
path: `/${m.id}${paramPart}`,
name: m.id,
component: m.component,
meta: { moduleId: m.id }
}
} catch (e) {
console.warn(`[router] 模块 ${m?.id} 路由生成失败,已跳过:`, e)
return null
}
})
.filter(Boolean)
const routes = [
{
path: '/',
redirect: moduleRoutes.length ? moduleRoutes[0].path : '/404'
},
// 每个模块一条路由,组件懒加载
...moduleRoutes,
{
path: '/:pathMatch(.*)*',
name: 'not-found',
redirect: '/'
}
]
const router = createRouter({
history: createWebHistory(),
routes,
scrollBehavior() {
return { top: 0 }
}
})
export default router