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 8351881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:47:02+00:00 2026-06-09T08:47:02+00:00

I’m using the router function in backbone.js and came across this problem. This may

  • 0

I’m using the router function in backbone.js and came across this problem. This may be a trivial thing, but I cant seem to figure this out nor find anything on Google.

Problem: On the page http://www.mydomain.com/user/1 there is a link. This link should link to http://www.mydomain.com/user/1/profile.

Of course if I use <a href="1/profile"> I get what I am looking for, but 1 is a dynamically generated value. How then should my router define the routes? I believe its not a wise choice to hardcode the number 1 into the routes.

//Router

var AppRouter = Backbone.Router.extend({

    routes: {
        '': 'profile',
        'profile': 'profile'
    },

    profile: function() {

    }
});

var app = new AppRouter();
Backbone.history.start();

When I set the href attribute of the a tag like <a href="profile">, the link that results is http://www.mydomain.com/user/profile.

For <a href="./profile"> I get http://www.mydomain.com/user/profile.

For <a href="/profile"> I get http://www.mydomain.com/profile.

For <a href="profile/"> I get http://www.mydomain.com/profile/.

Why is the 1 missing, and how can I keep it to achieve what I want?

  • 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-06-09T08:47:04+00:00Added an answer on June 9, 2026 at 8:47 am

    You can’t define this dynamic URLs directly in the HTML, you have to create them into your Views.

    For example:

    template:

    <script type="text/template" id="template-element">
      <h1><%= title %></h1>
      <a class="profile" href="<%= url_profile %>">profile</a>
    </script>
    

    js code:

    // code simplified and no tested
    var Element = Backbone.Model.extend({
      initialize: function(){
        this.set( "url_profile", this.url() + "/profile" );
      }
    });
    
    var ElementView = Backbone.View.extend({
      template: _.template( $("#template-element").html() ),
    
      render: function(){
        this.$el.html( this.template( this.model.toJSON() ) );
        return this;
      }
    });
    

    Or, as I do sometimes when I feel in the way:

    template:

    <script type="text/template" id="template-element">
      <h1><%= title %></h1>
      <a class="profile" href="#replace_with_real_url">profile</a>
    </script>
    

    js code:

    // no Element.url_profile attribute needed:
    var ElementView = Backbone.View.extend({
      template: _.template( $("#template-element").html() ),
    
      render: function(){
        this.$el.html( this.template( this.model.toJSON() ) );
        this.$el.find( ".profile" ).attr( "href", "/user/" + this.model.id + "/profile" );
        return this;
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.