xtraderClient/docs/core/router.md
2026-03-20 19:01:14 +08:00

36 lines
946 B
Markdown
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.

# router/index.ts
**路径**`src/router/index.ts`
## 功能用途
Vue Router 配置,定义路由表与滚动行为。
## 路由表
| path | name | component |
|------|------|-----------|
| / | home | Home |
| /search | search | Search |
| /trade | trade | Trade |
| /login | login | Login |
| /trade-detail/:id | trade-detail | TradeDetail |
| /event/:id/markets | event-markets | EventMarkets |
| /wallet | wallet | Wallet |
| /profile | profile | Profile |
| /api-key | api-key | ApiKey |
## 滚动行为
滚动目标为 `[data-main-scroll]`App.vue 内主滚动容器),非 window
-`savedPosition` 且来自已命名路由:恢复该容器的 `scrollTop`
-`to.hash`:滚动到锚点元素
- 否则:滚动到顶部
## 扩展方式
1. **路由守卫**`beforeEach` 做鉴权、重定向
2. **懒加载**`component: () => import('./views/Home.vue')`
3. **meta**:为路由增加 `meta.requiresAuth`