Skip to content

active-class is not given to named routes if the URL does not include the trailing slash / #826

Closed
@theshem

Description

@theshem

Consider the following snippet:

<router-link :to="{name: 'home'}" exact>Home</router-link>
<router-link to="/user">/user (2) </router-link>
<router-link :to="{name: 'user'}">user (named route) (3) </router-link>

<router-view></router-view>
const router = new VueRouter({
  mode: 'history',
  routes: [
    { 
      path: '/user', 
      component: User,
      children: [
        { 
          path: '',
          name: 'user',
          component: UserHome 
        }
      ]
    },
    {
      path: '',
      name: 'home',
      component: Home,
    }
  ]
});

Example here - click on the link (2), then click on the Home and finally click on the link (3).

Notice that the link (2) and link (3) are 'exact' same routes. But they both don't get the active-class at the same time if you click on the link (2).

However the active-class is added to both of them by clicking on the link (3).

That is because of the trailing slash / on the (3) link I guess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions