Git Product home page Git Product logo

Comments (5)

Anthodpnt avatar Anthodpnt commented on August 10, 2024

Hi @RoyVeldman,

Can you give us a more solid description by including pieces of code so we can have an idea about how you deal with your links ?

Best regards,
Anthodpnt

from highway.

RoyVeldman avatar RoyVeldman commented on August 10, 2024

Yes sorry,

These are the links

<div class="indicators">
       {% for item in craft.entries.section('products').all() %}
             <a href="{{ item.url }}" class="cool-btn" data-transition="productPage">
                  <span>{{ loop.index }}</span>
                  <span>{{ item.title }}</span>
             </a>
     {% endfor %}
 </div>

My app.js

const H = new Highway.Core({
   renderers: {
      
   },
   transitions: {
      default: Fade,
      contextual: {
         productPage: productPageTransition
      }
   }
});

For the nav active class I use your code, I only changed the querySelector

// Get all menu links
const links = document.querySelectorAll('.indicators a');

// Listen the `NAVIGATE_IN` event
// This event is sent everytime a `data-router-view` is added to the DOM Tree
H.on('NAVIGATE_IN', ({ to, location }) => {
  // Check Active Link
  for (let i = 0; i < links.length; i++) {
    const link = links[i];

    // Clean class
    link.classList.remove('is-active');

    // Active link
    if (link.href === location.href) {
      link.classList.add('is-active');
    }
  }
});

from highway.

Anthodpnt avatar Anthodpnt commented on August 10, 2024

Hi @RoyVeldman,

The only issue I could see would be that your links might be in the data-router-view meaning that you have to select them inside the NAVIGATE_IN event to make sure that you get the right links from the right data-router-view.

In the documentation the example is based on a list of links outside the data-router-wrapper meaning that they stay the same during navigation and so they can be selected once outside the NAVIGATE_IN event. But if the links are located inside the data-router-view elements that are swapped during navigation you have to get them back every time the DOM change using the events.

It's hard to be more precise but I suppose this is that kind of issue you get here since the documentation has been tested multiple times and is even running on the documentation website without any problem. Unfortunately this is more a problem related to your code than a problem coming for Highway.

Keep me in touch if I spotted the issue or if you find it yourself.
Best regards,
Anthodpnt

from highway.

RoyVeldman avatar RoyVeldman commented on August 10, 2024

@Anthodpnt Thanks for replying so quick, but yes I guess that was the issue indeed, my links are inside my data-router-view. I am switching the active class now with adding and removing the classes based on to and from querySelector in my contextual transition file.

from highway.

Anthodpnt avatar Anthodpnt commented on August 10, 2024

@RoyVeldman So I assume that your problem is resolved and that I can close this issue.

from highway.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.