Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:02:09+00:00 2026-05-30T20:02:09+00:00

EDIT : this question is very similar to this one but it’s more conceptual

  • 0

EDIT: this question is very similar to this one but it’s more “conceptual” one.

Assume a single-page app with a bounce of static links that reflects routes:

<!-- Top navlist -->
<ul class="nav nav-list">
    <li><a class="active" href="#/customers">Customers</a></li>
</ul>

<!-- Left navlist -->
<ul class="nav nav-list">
    <li><a class="active" href="#/customers">Show customers</a></li>
    <li><a href="#/customers/new">Create customer</a></li>
</ul>

I need to set class="active" for one (or more) links based on the current route. Which is the correct approach?

  1. Create Link and LinkCollection models, as long as LinkCollectionView and LinkView, from scratch: this seems overkill to me. And seems useless since links not depend upon server side (they are not dynamically created).
  2. Create Link and LinkCollection models iterating over existing links.
  3. Forget about models and view and manually set class="active" for each route. Something like $('body').find('a[href="#/customers"]').addClass('active'). Seems a duplication of code to me.
  4. Create a “global” AppView view and do something like pt. 3 in render() funcion.

Routes definition example:

<script>
    (function($){
        var MyApp = { Models : {}, Collections : {}, Views : {} };

        // The Router
        MyApp.Router = Backbone.Router.extend({
            routes : {
                '/customers'     : 'showCustomersView',
                '/customers/new' : 'showCreateCustomerView'
            },
            showCustomersView      : function() {
               // Make customers links active
            },
            showCreateCustomerView : function() {
               // Make new customer links active
            },
        });

    })(jQuery);
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:02:10+00:00Added an answer on May 30, 2026 at 8:02 pm

    I can’t speak to the “best practice”, but I am fairly certain that involving models solely for the purpose of representing intra-app links is, as you said, definitely overkill and not their intended use.

    I personally would do something like pattern #4. In a project I am currently working on, I have an AppView that looks a little something like this:

    AppView = Backbone.View.extend({
    
      events: {
        "click a.internal" : "handleLink"
      },
    
      handleLink: function (event) {
        var route = $(event.target).attr('data-route');
        router.navigate(route, true);
        return false;
      },
    
    });
    

    I do not use the actual href property on my anchor tags to specify the target route, as I am using pushState. Instead, I use an element class, internal, to indicate an anchor tag which is to be used for my app’s internal navigation. I then use another arbitrary element attribute, route, to indicate where the link ought to be going.

    A link might look like something like this, then:

    <a href="#" class="internal" data-route="projects/3">My Third Project</a>

    Adding in the extra bit to add that CSS class you want would then just be a matter of making a jQuery/Zepto call in handleLink.

    Again, I don’t necessarily believe this is a common/best practice, but at least for my purposes it seems to be sufficiently simplistic and straightforward (and also works with pushState).

    Edit: Use steveax’s suggestion of data-route for syntax validity sake.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may be very similar to my one, but I cannot see the
I found a question that was very similar to this one, but using features
This question is similar to this one , but hopefully it will pick up
Firstly, I realise that this is a very similar question to this one: Which
I have asked a very similar question, but I ended up using images instead
My apologies if this looks very much like a similar question I asked a
Referring on this question , I have a similar -but not the same- problem..
Bit of a n00b question this one, I guess, but here goes. As part
I am aware of this question , but I believe my concerns are very
Edited 3.9.2011 to add one more related question Hello, I'm very new to WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.