Stephan-v
Stephan-v

Reputation: 20289

Vue router alias priority

I have two routes that I have set up in my routes file like this:

{
    path: '/:language?/chain/:entity/',
    alias: '/:language?/:entity/',
    name: 'search',
    component: Search
}

Because the path route is more specific than the alias I have put it as my main path.

This works for something like:

/de/chain/mcdonalds/

However for something like this it doesn't work:

/de/mcdonalds/

Because my main path is /:language?/chain/:entity/ it will still insert chain into all my router-link components. Even though it does not match the exact word.

I want that route to take precedence if it matches though. If I swap them around I will inverse my entire situation.

How can I get both of these routes to work properly?

Upvotes: 2

Views: 3122

Answers (1)

Daniel
Daniel

Reputation: 35684

Unfortunately, until dynamic aliases are supported by vue-router, this feature is not possible.

You will likely need to do this in the meantime

{
  path: '/:language?/chain/:entity/',
  name: 'search',
  component: Search
},
{
  path: '/:language?/:entity/',
  name: 'search',
  component: Search
}

Here is the Github link for feature request: https://github.com/vuejs/vue-router/issues/1858

Upvotes: 4

Related Questions