Files
testing-tool/sidepanel/js/index.js
T
雨霖铃 8cb9580860 refactor(router): 优化路由重定向配置与组件初始化逻辑
- 设置默认重定向路由为 '/'
- 修复路由实例化后未正确调用 init 方法的问题
- 移除不必要的控制台日志输出
- 调整路由守卫中 next 回调的参数传递方式
- 导出 Router 类时增加空格以符合代码风格
- 更新时间戳组件导入方式并移除冗余初始化调用
- 为定时器管理器添加清理功能的日志提示
- 从 BaseComponent 中移除调试日志并修复定时器返回值处理
2025-12-13 21:52:52 +08:00

50 lines
1.2 KiB
JavaScript

import {ScriptManager} from './utils/scriptManager.js';
import {TimerManager} from './utils/timerManager.js';
import {EventManager} from './utils/eventManager.js';
import {Router} from '../modules/Router.js';
const config = {
routerViewId: 'app',
stackPages: false,
redirectRoute: '/',
routes: [
{
path: '/',
name: 'timestamp',
html: 'pages/timestamp.html',
script: '../dist/timestamp.js',
},
{
path: '/home',
name: 'timestamp',
html: 'pages/timestamp.html',
script: '../dist/timestamp.js',
},
{
path: '/todo',
name: 'todo',
html: 'pages/todolist.html',
},
],
};
// 注入脚本管理器
window.scriptManager = new ScriptManager();
// 注入定时器管理器
window.timerManager = new TimerManager();
// 注入事件管理器
window.eventManager = new EventManager();
const router = new Router();
router.init(config);
// click delegation
document.addEventListener('click', (e) => {
const btn = e.target.closest('[data-route]');
if (!btn) return;
const p = btn.getAttribute('data-route');
location.hash = p;
// update active styling
document.querySelectorAll('[data-route]').forEach((b) => b.classList.toggle('active', b === btn));
});