Skip to content

Commit

Permalink
refactor(router): extract matchRoutes()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 22, 2020
1 parent 130dff6 commit d5917ec
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/router/src/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,7 @@ export class BasicRouter implements INotify {
src = src.substr(1);
}
src = src.substr(this.config.prefix!.length);
const routes = this.config.routes,
curr = src.split(this.config.separator!);
let match;
for (let i = 0, n = routes.length; i < n; i++) {
const route = routes[i],
m = this.matchRoute(curr, route);
if (m) {
match = m;
break;
}
}
let match = this.matchRoutes(src);
if (!match) {
if (!this.handleRouteFailure()) {
return;
Expand Down Expand Up @@ -164,6 +154,17 @@ export class BasicRouter implements INotify {
return this.config.routes.find((route) => route.id === id);
}

protected matchRoutes(src: string) {
const routes = this.config.routes;
const curr = src.split(this.config.separator!);
for (let i = 0, n = routes.length; i < n; i++) {
const match = this.matchRoute(curr, routes[i]);
if (match) {
return match;
}
}
}

protected matchRoute(curr: string[], route: Route): RouteMatch | undefined {
const match = route.match,
n = match.length;
Expand Down

0 comments on commit d5917ec

Please sign in to comment.