Skip to content

[Feat] Sort routes by path and exact on registering #48

Closed
@meeroslav

Description

@meeroslav

This is precondition to guards on RouteComponent using structural directive.

At the moment, each route with structural directive will be registered asynchronously, landing in the routes array most likely after wildcard/catch-all route. Additionally, this allows user to define routes without worrying about the correct order.

Rough logic:

this.routes$ = this._routes$.pipe(scan((routes, route) => {
  routes = routes.concat(route).sort((a, b) => {
    if (b.path < a.path) { return -1; }
    if (a.path < b.path) { return 1; }
    if (a.options.exact < b.options.exact) { return -1; } // additional checks for missing `exact` param needed
    if (a.options.exact > b.options.exact) { return 1; }
    return 0;
  });
  return routes;
}));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions