Skip to content

Commit af2b2aa

Browse files
committed
refactor(router): 优化路由类型定义和简化路由对象
- 重构types.ts文件,重新组织类型定义结构并添加详细文档注释 - 简化Route接口,移除冗余的URL属性,直接使用loc对象 - 调整isSameRoute和isEqualRoute参数顺序,保持一致性 - 更新RouterMicroApp相关类型定义,增强类型安全性 - 添加完整的JSDoc注释说明各类型用途和使用方式
1 parent ed36eda commit af2b2aa

File tree

4 files changed

+504
-145
lines changed

4 files changed

+504
-145
lines changed

packages/router/src/next/guards.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Route } from './types';
33
/**
44
* 判断是否是同一个路由
55
*/
6-
export function isSameRoute(from: Route, to: Route) {
6+
export function isSameRoute(to: Route, from: Route) {
77
return (
88
from.matched.length === to.matched.length &&
99
from.matched.every((record, i) => record === to.matched[i])
@@ -13,7 +13,7 @@ export function isSameRoute(from: Route, to: Route) {
1313
/**
1414
* 判断是否是全等的路由: 路径完全相同
1515
*/
16-
export function isEqualRoute(from: Route, to: Route) {
16+
export function isEqualRoute(to: Route, from: Route) {
1717
return (
1818
// 这里不仅仅判断了前后的path是否一致
1919
// 同时判断了匹配路由对象的个数

packages/router/src/next/route.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ export function createRoute(
133133
export function createRouteByURL(loc: URL): Route {
134134
return {
135135
loc: loc,
136-
hash: loc.hash,
137-
host: loc.host,
138-
hostname: loc.hostname,
139-
href: loc.href,
140-
origin: loc.origin,
141-
pathname: loc.pathname,
142-
port: loc.port,
143-
protocol: loc.protocol,
144-
search: loc.search,
145136
params: {},
146137
query: {},
147138
queryArray: {},

packages/router/src/next/router.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import type {
66
NavigationResult,
77
Route,
88
RouteState,
9-
RouterMicroApp,
109
RouterMicroAppCallback,
10+
RouterMicroAppOptions,
1111
RouterOptions,
1212
RouterParsedOptions,
1313
RouterRawLocation
1414
} from './types';
1515
import { isBrowser } from './util';
1616

1717
class MicroApp {
18-
public app: RouterMicroApp | null = null;
18+
public app: RouterMicroAppOptions | null = null;
1919
private _factory: RouterMicroAppCallback | null = null;
2020
public _update(router: Router) {
2121
const factory = this._getNextFactory(router);
@@ -191,7 +191,7 @@ export class Router {
191191
return handleRoute({
192192
navType,
193193
options: this.options,
194-
loc: loc ?? this.route.href,
194+
loc: loc ?? this.route.loc.href,
195195
handle: async (result) => {
196196
await this._applyRoute(result.route);
197197
return result;

0 commit comments

Comments
 (0)