Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
meeroslav opened this issue Aug 19, 2020 · 0 comments
Closed

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

meeroslav opened this issue Aug 19, 2020 · 0 comments
Assignees

Comments

@meeroslav
Copy link
Collaborator

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;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant