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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:50:25+00:00 2026-06-17T16:50:25+00:00

Sorry, the title is a little confusing. My backbone router has the following structure:

  • 0

Sorry, the title is a little confusing.

My backbone router has the following structure:

var AppRouter = Backbone.Router.extend({
    routes: {
      'notes': 'showNotes',
      'news': 'showNews'
    },
    showNews: function() {
        // make view object and render
    },
    showNotes: function() {
        // make view object and render
    },
    initialize: function() {
        this.user.fetch({success: function(){
            // callback function
        }});
    }
});

The issue I am having is that i need to pass the user into the views, so i need each render to only run if the success callback runs inside of initialize. Basically I don’t want initialize to finish until the callback is called. I cant figure out how I could achieve this.

Thanks

  • 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-17T16:50:25+00:00Added an answer on June 17, 2026 at 4:50 pm

    Router#initialize, by default, is an empty function. At the point it’s run, the routes have already been handed off to History, and you’re probably past any “clean” way to prevent them.

    If you really need to ensure that your user is fetched before the router starts rendering, you could achieve that by fetching the user before the history begins, something like this:

      // in some initializer:
      user.fetch({success: function() {
        var router = new AppRouter({user: user});
        Backbone.history.start();
      }});
    
      // and your router:
      initialize: function(options) {
        if (options) this.user = options.user;
      }
    

    But it may also make sense to have the view respond to the user being fetched, rather than ensuring that it’s loaded beforehand. The view might simply render nothing until the user loads, or it might show a “loading” graphic, etc. In which case you’d just:

    // in your router
    showNotes: function() {
      // note sure how you're storing your views, but for example:
      this.currentView = new ShowNotesView({model: this.user}).render();
    },
    
    initialize: function() {
      this.user.fetch();
    }
    
    // and in the view
    initialize: function() {
      this.model.on('sync', this.render.bind(this));
    },
    
    render: function() {
      // note that `hasBeenSynced` is a made up property.  Fill it in with something
      // that indicates the model has been fetched successfully.  Alternatively you
      // might do this in the template.  Lot of flexibility here.
      if (this.model.hasBeenSynced) {
        // render the model
      } else {
        // show nothing, a loading template, etc
      }
      return this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if the title is a little confusing. What I'm doing is creating a
Sorry if the question title is a little confusing, but I'm not sure exactly
Sorry if the title is a little confusing. Here's what I meant - I
I'm sorry for the little confusing title but say I have a class with
Sorry if the title is a little vague, I have the following sceneraio: I
Sorry if the Title is a little vague but the truth is I do
Sorry if the post title wasn't clear, I will try to explain a little
Sorry if the title is a little... vague. Anyway, I'm making a platformer using
I'm sorry if my title is a little unclear. Basically I want to print
Sorry if the title is a little weird... but basically want I want to

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.