I have a routing structure such as:
{
path: '/post/'
component: Post,
children: [
{
path: '/',
component: Text,
},
{
path: 'text/',
component: Text,
},
{
path: 'video/',
component: Video,
},
],
}
The important thing is that the route
/post/text/
is just an "alias" to the/post/
(root point in this case). Also the router configuration has the customlinkActiveClass
option such as 'act' with some defined styles.
In the parent template I have the kind of tabs with router-link
's:
<ul>
<li>
<router-link to="/post/text/">Text</router-link>
</li>
<li>
<router-link to="/post/video/">Video</router-link>
</li>
</ul>
So the question is: when going to the /post/
route it would be nice the Text tab to be marked as "active" with that 'act' class because it's just a duplicate of the /post/text/
(or vice versa).
I haven't found any mention of this in the Vue Router
docs. How such problems are solved competently?
Thanks in advance!
Solution (TL;DR - currently unsupported, fixed in v4)
The easiest way to achieve this - to use route alias
prop, like:
{
path: 'text/',
component: Text,
alias: '/',
},
But, unfortunately, active-class
doesn't work properly with aliases yet. It has been fixed in Vue Router v4.