Skip to content

Improve routes priorization #335

@srosset81

Description

@srosset81

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));
    },
  }

Metadata

Metadata

Assignees

No one assigned

    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