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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:55:50+00:00 2026-06-13T05:55:50+00:00

Looking at this example it appears that the router should detect links causing a

  • 0

Looking at this example it appears that the router should detect links causing a change in URL that match its routes. However, clicking on the link generated by my Handlebars template only changes the URL and does not trigger the alert in the router. The route is, for some strange reason, triggered upon refresh, though the URL looses the hash.

I’m not sure why the router isn’t picking up my URL change. I’d prefer using links rather than Router.navigate if they do work. The route does work for the default route.

The backbone.js code below is run on $(document).ready from a script in the html head.

Item Handlebars template

{{#with lobby}}
<li id="lobby-{{id}}">
    <div class="lobby_info">{{name}} - {{owner}} - {{player_count}}/18</div> <a href="#lobby/{{id}}">Join</a>
 </li>
 {{/with}}

Item Backbone View

var LobbyView = Backbone.View.extend({
    events: {
        "click .lobby_info": "expand_toggle",
    },

    expand_toggle: function(evt) {
        alert('Expand toggle');
    },

    render: function() {
        var template = Handlebars.compile($("#lobby_template").html());

        this.$el.html(template(this.model.toJSON()));

        return this;
    }
});

Item Collection View

var LobbiesView = Backbone.View.extend({
    events: {
        "submit #create_lobby_form": "create_lobby",
    },

    create_lobby: function(evt) {
        evt.preventDefault()

        var val = $('#lobby_name').val();

        socket.emit('create', val);

        $("#lobby_name").val("");
    },

    initialize: function() {
        var me = this;

        socket.on('create', function(lobby) {
            var lobby_item = new LobbyView({
                model: new LobbyModel({
                    lobby: lobby
                })
            });

            // render it to the DOM
            el = lobby_item.render().el;
            me.$("#lobbies").append(el);
       });

    },

    render: function() {
        var me = this;

        var template = Handlebars.compile($("#lobbies_template").html());

        $(this.el).html(template());

        return this;
    },
});

Router

var Router = Backbone.Router.extend({
    // Match urls with methods
    routes: {
        "": "index",
        "lobby/:lobby_id": "lobby",
        "player/:player_id": "player"
    },

    index: function() {
        // connect to the websocket
        socket = io.connect();
        socket.emit('subscribe');
        var view = new LobbiesView({
            el: $("#container"),
        });

        view.render();
    },

    // View a lobby
    lobby: function(lobby_id) {
        alert('Viewing lobby' + lobby_id);
    },

    // View a player
    player: function(player_id) {
    },
});

// start backbone routing
var app = new Router();
Backbone.history.start({ pushState: true });
  • 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-13T05:55:52+00:00Added an answer on June 13, 2026 at 5:55 am

    Your issue is { pushState: true }. Remove it and your router will work (tested in console). If pushState is set to true, you need to set up routes without hashes.

    This is the code I was testing:

    var Router = Backbone.Router.extend({
        routes: {
            "": "index",
            "lobby/:lobby_id": "lobby",
            "player/:player_id": "player",
            "*actions": "test"
        },
    
        test: function() { 
            console.log('test', arguments) 
        },
    
        index: function() {
            console.log('index', arguments);
        },
    
        player: function() {
            console.log('player', arguments);
        },
    
        lobby: function(lobby_id) {
            console.log('lobby', arguments);
        }
    });
    
    // start backbone routing
    var app = new Router();
    Backbone.history.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking at this jQuery example, how can I modify the code so that it
looking at this example of the jquery ui slider http://jqueryui.com/demos/slider/#steps i want to be
I was just looking at this example from Deitel : #include <stdio.h> struct card
I am looking at this example: List<Product> products = Product. GetSampleProducts() ; products.Sort( (first,
thank you for looking i got this example from my book but i cant
Looking for a proven to work algorithm for production. Did see this example but
I've searched this site and the web and just looking for a simple example
I'm looking for an example of using OpenSSL's AES CCM encryption. Apparently, this is
I'd like to specify a Servlet URL pattern to match a URL that ends
I am looking at a code example, and I am not sure what this

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.