1

Not sure how to word the question which is probably why I haven't found a solution when looking through stackoveflow for a solution. But...

When I try to implement code like the sample found here that attaches an active class to the nav links (https://coderwall.com/p/ahlrua) I sometimes have to hit refresh after navigating to a new page to see that link actually goes active. My guess is that since the js file has already been loaded to the client-side there is no subsequent call to the file when I navigate to new pages? If this is the case, even if not, how the heck do I fix this?

This behavior as I mentioned happens in other places for me when I use Meteorjs, ie my breadcrumbs always need refreshing after going to a new page. I'm fairly new to this framework so forgive my ignorance.

Here's my staging site that I'm working on that has this/these issues: http://jdd.meteor.com/

Thank you in advance for your time and consideration :)

1 Answer 1

2

You need to refresh browser to see active link because code responsible for activating link is not reactive :

// Get the current path for URL
curPath = function() {
  var c = window.location.pathname;
  var b = c.slice(0, -1);
  var a = c.slice(-1);
  if(b === "") {
    return "/";
  } else {
    if(a === "/") {
      return b;
    } else {
      return c;
    }
  }
};

It only checks the url when template is being rendered not when window.location.pathname is changed.

One of possible solutions is to use IronRouter together with package IronRouterActive.

Usage is very simple:

<nav>
    <ul>
        <li class="{{ isActiveRoute 'dashboard' }}">...</li>
        <li class="{{ isActiveRoute 'dashboard|root' }}">...</li>
        <li class="{{ isActiveRoute 'users' 'on' }}">...</li>
        <li class="{{ isActivePath 'products' }}">...</li>
    </ul>
</nav>

Example source

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I will give that a go. However, this problem pervades other aspects of my site (ie breadcrumbs). Perhaps when I look into this though it will also remedy that situation. Will try this later today. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.