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

Improve routes priorization #335

Open
srosset81 opened this issue Sep 18, 2023 · 1 comment
Open

Improve routes priorization #335

srosset81 opened this issue Sep 18, 2023 · 1 comment

Comments

@srosset81
Copy link

srosset81 commented Sep 18, 2023

When routes are added via the addRoute action, it's difficult to control the priority of the routes added. The toBottom parameter doesn't work well because if other services call addRoute later, their routes will be added below.

This is a problem especially when there are catch-all routes which must imperatively be handled at the very end.

A solution could be to set a priority option (as a number) to routes. Higher-priority routes would bypass lower-priority routes in the optimizeRouteOrder method.

What do you think ?

For now I've found a temporary solution by adding a catchAll option to routes and overwriting the optimizeRouteOrder method to ensure these catch-all routes are handled last:

  methods: {
    optimizeRouteOrder() {
      // Overwrite optimization method to put catchAll routes at the end
      this.routes.sort((a, b) => (a.opts.catchAll ? 1 : -1));
      this.aliases.sort((a, b) => (a.route.opts.catchAll ? 1 : -1));
    },
  }
@icebob
Copy link
Member

icebob commented Sep 18, 2023

Good idea, a priority route setting can be good. Could you work on a draft PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants