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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:24:53+00:00 2026-05-31T16:24:53+00:00

I have a Base Router where i define some functions that need to be

  • 0

I have a Base Router where i define some functions that need to be run everywhere. Every Router extends this Router.

Now my problem is, that none of my routes defined in this Base router, actually fire. Every other route in other Routers work fine. I have created a test route called ‘a’ which calls method ‘b’, which should fire an alert but nothing happens.

Here is the code: (This is Coffeescript, don’t pay attention to the indentation, it’s fine in my file)

class Etaxi.Routers.Base extends Backbone.Router

routes:
    'register' : 'registerDevice'
    'a' : 'b'

b: ->
    alert "a"

initialize: ->
    @registerDevice() unless localStorage.device_id?
    @getGeolocation()

registerDevice: ->
    @collection = new Etaxi.Collections.Devices()
    @collection.fetch()
    view = new Etaxi.Views.RegisterDevice(collection: @collection)
    $('#wrapper').append(view.render().el)

getGeolocation: ->
    navigator.geolocation.getCurrentPosition (position) ->
        lat = position.coords.latitude
        lng = position.coords.longitude
        #$('#apphead').tap ->
        #   alert 'Position: ' + lat + " ," + lng

So when i visit ‘/register’ or ‘/a’ it should fire the appropriate method but it does not. I wonder if it has something to do with the fact that other Router extend from this Router? Would be wired but it is the only thing i can think of because every other Router works fine.

Update

I think i have found a workaround by instantiating the Base Router in my main app .js file. This is what i do now:

new Etaxi.Routers.Base() (this is the new one)
new Etaxi.Routers.Videos()

Do you see any possible issues with this?

  • 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-31T16:24:54+00:00Added an answer on May 31, 2026 at 4:24 pm

    The problem is that extends won’t merge properties in your classes, the subclass’s properties will completely replace the superclass’s. For example, given these:

    class Etaxi.Routers.Base extends Backbone.Router
        routes:
            'register' : 'registerDevice'
            'a' : 'b'
    
    class R extends Etaxi.Routers.Base
        routes:
            'c': 'd'
    

    Then the routes for an instance of R will be just 'c': 'd'. Here’s a demo with plain (non-Backbone) CoffeeScript classes: http://jsfiddle.net/ambiguous/ScUs2/

    If you need to merge properties, you’ll have to do it yourself with something like this:

    class M
        m: { a: 'b' }
    
    class Pancakes extends M
        constructor: ->
            @m = _({}).extend(@m, a: 'B', c: 'd')
    

    Demo: http://jsfiddle.net/ambiguous/SR6ej/

    But that sort of trickery won’t work with Backbone.Router as the construction sequence is a bit different:

    var Router = Backbone.Router = function(options) {
      options || (options = {});
      if (options.routes) this.routes = options.routes;
      this._bindRoutes();
      this.initialize.apply(this, arguments);
    };
    

    So the @routes need to be properly set up before initialize is called; that means that you can’t merge new routes into @routes in your initialize and expect them to be hooked up. Also, you probably don’t want to provide your constructor when using Backbone as you’d have to fully implement the standard Backbone.Router constructor and slip your extra stuff in the middle of it.

    A couple options immediately present themselves:

    1. Manually add the subclass’s routes by calling route in the subclasses initialize.
    2. Leave the routes out of the base class, add a method to the base class that adds the base class’s routes using route calls, and then call that method in the subclass initialize method.

    Another possible option would be to do something like this:

    class R extends Backbone.Router
        routes:
            'a': 'b'
    
    class RR extends R
        @::routes = _({}).extend(R::routes, 'c': 'd')
    

    That should get you { 'a': 'b', 'c': 'd' } in the subclass’s routes at the right time; I haven’t fully tested this one but it does work in a simple demo: http://jsfiddle.net/ambiguous/QQbrx/

    All the messing around might be pointless though. You can have as many routers as you want so subclassing might be wholly unnecessary. For example, this works just fine:

    class R extends Backbone.Router
        routes:
            'a': 'b'
        b: -> console.log('b')
    
    class RR extends Backbone.Router
        routes:
            'c': 'd'
        d: -> console.log('d')
    
    new R
    new RR
    Backbone.history.start()
    

    Demo: http://jsfiddle.net/ambiguous/mr83v/

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

Sidebar

Related Questions

In the project I'm working on now, we have base Entity class that looks
I have a base page, BasePage, that raises an event that displays messages to
I have a base class that represents a database test in TestNG, and I
I have a base class that has a private static member: class Base {
Here's the scenario. We have a router that port forwards requests for our different
Right now I'm using this which works for the development host, but I have
I have decided that all my WPF pages need to register a routed event.
Ok here is the problem in brief. I do have a pyramid setup that
I have a couple classes that can each have comments: class Movie < ActiveRecord::Base
I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC

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.