I want to get path in order to set active class for active tabs. The code works, if I click "refresh" everytime.
Here is my code:
JS
Template.header.helpers({
isCurrentPage: function(pageName){
var pathArr = window.location.pathname.split("/");
var firstLevelPath = pathArr[1];
return firstLevelPath == pageName
}
});
HTML
<li role="presentation" class="{{#if isCurrentPage 'browse'}}active{{/if}}"><a href="{{pathFor 'browse'}}">Browse</a></li>
Full repo
Iron.Location.get().path
返回实际路径并且是反应性的,所以我猜你可以使用它
The window object is not reactive then the template does not know about the change. Try to use Tracker.autorun around it to have a reactive behavior.
Check this link that contains more about Tracker
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.