Implementing an active class in Vue.js for the router-link component

I am facing an issue with my sidebar item becoming inactive when I click on a sublink inside a component. How can I prevent the active class from switching off?

Here is my sidebar:

<router-link to='/sub/success_tools_subscriptions'
             class="list-group-item justify-content-between g-brd-none list-group-item-action"
             active-class="active">
  <i class="icon-feed g-pos-rel g-top-1 g-mr-8"></i>
  My subscriptions
</router-link>

This is my component (the page opened when clicking on the sidebar item):

<template>
<...>
        <profile-sidebar v-if="isMySubscriptionsPage" />
        <another-profile-sidebar v-else="" />
              <h1 class="g-mt-minus-10 g-font-stag-medium g-color-gray-dark-v2 g-mb-15">
                My subscriptions
              </h1>
                <div>
                  <router-link to="/sub/success_tools_subscriptions">Success Tools</router-link>
                </div>
                <div class="g-mx-10">|</div>
                <div>
                  <router-link to="/sub/qa_subscriptions">Questions and Answers</router-link>
                </div>
              </div>
              <router-view></router-view>
<...>
</template> 
<script>
import AuthLayout from '../components/layouts/AuthLayout';
import ProfileSidebar from '../components/profile/ProfileSidebar';
import AnotherProfileSidebar from  '../components/AnotherProfile/AnotherProfileSidebar';


export default {
  components: {
   ProfileSidebar,
   AnotherProfileSidebar,
 },
computed: {
  isMySubscriptionsPage() {
    return this.$route.path === '/sub/success_tools_subscriptions'
      || this.$route.path === '/sub/qa_subscriptions';
     },
    },
   };
</script>

The page has children defined in the router.js as follows:

{
  path: '/sub',
  redirect: '/sub/success_tools_subscriptions',
},
{
  path: '/sub',
  component: MySubscriptionsPage,
  children: [
    {
      path: 'success_tools_subscriptions',
      component: MySuccessToolsSubscriptions,
    },
    {
      path: 'qa_subscriptions',
      component: MyQaSubscriptions,
    },
  ],
},

Answer №1

Implemented active-classes to all sublinks nested under the primary heading h1.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the stroke and fill colors of an SVG element when hovering over it

I am facing a challenge with an SVG image that I have: https://i.stack.imgur.com/r4XaX.png When hovered over or clicked, it should change to https://i.stack.imgur.com/EHRG2.png Current Icon <svg width="24" height="24" viewBox="0 0 24 24" fill="non ...

Send the context parameter value of Unified Service Desk to a JavaScript web resource in CRM

Currently, I am working on CRM 8.2 and Unified Service Desk 4.1. I have a specific requirement where I need to pass parameter values from within Unified Service Desk Data Parameters to a JavaScript Webresource. I have come across some resources that sugge ...

Prevent automatic merging of JSON data with identical IDs

My AJAX call to a PHP select request is as follows: $.ajax({ type: "POST", url: "/renforts/_getIntervenantManager", data: { IDMission : IDMission, IDManager : IDManager }, dataType : 'json' ...

Could someone explain why the window.onload function is not functioning as expected on my other Vue page?

I am facing an issue with my two pages or "views" that have identical JS code. Both pages have a window.onload function where I perform some actions: console.log("loading") window.onload = function() { console.log("loaded") // do stuff } The problem is t ...

Ways to extract information immediately after using the .load method

Is there a way to instantly store data from .load in JavaScript? Whenever I use .load within a JavaScript function to retrieve content from the server and display it on the browser page, the content does not update immediately. It's only when the fu ...

Unusual Methods in Vue.js: Exploring Odd Behavior

In my application, I have a single data variable called message, as well as a method in the methods section that performs cryptographic algorithms. Below is the code snippet: export default { data: () => ({ message: "" }), methods: { clic ...

Why isn't it working if this.setState is not available?

Hey there, I'm having some trouble with my this.setState function in React. It works fine in other files but not here, even though the code is identical. Can anyone help me figure out why? test(event){ event.preventDefault(); var regex_mongoinclude = ...

Conceal an element from view upon clicking on it

Task at Hand : Implement a smooth element hiding effect upon clicking, similar to the behavior on this website , where the letter A fades away smoothly when clicked. Is it possible to achieve this effect using only HTML, CSS, and JavaScript? var t ...

Bottom-aligning text in Tailwind CSS

Creating two <p> tags to store text: <p v-if="my_property <= 0" class="text-green-500 text-lg font-bold">{{Math.abs(my_value)}}%</p> <p v-else class="text-red-500 text-lg font-bold">{{my_value}}%< ...

Is the window frozen while Ajax processes the request?

When I make an ajax request that may take a significant amount of time to process on the server-side, I want to display a loading image during the request. However, the loading image is not showing up while the ajax request is processing. var ref = create ...

Javascript datatables do not allow for setting a default column sort

I am encountering an issue where I need to sort the results by a specific column on page load. In this case, I want the initial results to be displayed in descending order based on "RecordDate". However, it seems that the server side is blocking any sort ...

Exploring the process of incorporating types for a Vue plugin

I am currently trying to integrate a self-made plugin for Vue with TypeScript. However, when I try to use the method from my vue prototype, I encounter an issue where my method $auth is not recognized on type 'myComponent'. I have also included ...

Vue.js - Communicating attribute names with a Child component

Currently, I am in the process of developing a Vue SelectComponent. One of the requirements I have is to pass the name of the Select as an attribute to the component like this: <select-component selectName="providers"></select-component> With ...

Executing multiple functions in a specific order within an asynchronous grunt task using async

I am facing an issue with my grunt tasks that run asynchronously using this.async. I have some asynchronous functions in the code and for a few tasks, I need them to run in series. To achieve this, I am utilizing async.series from the async npm module. How ...

Tooltipster fails to function with elements that are dynamically created

I've been struggling with this issue for several days now, but I can't seem to find a solution. In my JavaScript code, I have a function that generates HTML after an Ajax call is completed. I call this function in the following manner: $(documen ...

Adding next-auth middleware on top of nextjs middleware in Nextjs implementation

I am in need of the nextjs middleware to be activated for two distinct paths: Firstly, to serve as a protection against unauthorized access by utilizing next-auth. Secondly, to redirect authorized users from specific pages. For example, if an authorized u ...

Issues with Imported Routes Not Functioning as Expected

I am currently working on implementing routing in my Angular 2 project. All the components are functioning properly, but I encounter an error when I include 'appRoutes' in the imports section of app.module.ts. An unexpected TypeError occurs: C ...

How can I load only specific images on a webpage using HTML?

I attempted to implement an image filter for my website by using the code below: <script> function myFunction() { // Initialize variables var input, filter, ul, li, a, i; input = document.getElementById('myInput'); filter = input.value.toU ...

Tips on creating an inline editable cell in a Tree View

I've been working on a category tree that includes expand and collapse buttons. You can see what I have so far here: Category Tree Now, I'm looking to make each item inline editable. Can someone guide me on how to achieve this? If you want to t ...

What is the best way to describe duplicate keys within a JSON array?

I have created a specialized program to extract Dungeons and Dragons data from JSON files. While the main functionality is complete, I am struggling with defining unique keys for multiple attack options without manually assigning individual identifiers. H ...