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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:22:47+00:00 2026-06-08T11:22:47+00:00

Will Backbone.Router.navigate set test to true : var test = false; var Router =

  • 0

Will Backbone.Router.navigate set test to true:

var test = false;

var Router = Backbone.Router.extend({
  routes: {
    'posts': 'showPosts'
  },
  showPosts: function () {
    test = true;
  }
});

router = new Router();
Backbone.history.start();

router.navigate('posts?foo=3', {trigger: true});

assert.ok(test);

Eg, will posts?foo=3 fragment will match the posts route by default, or do I have to set another route for that, for example: posts?*querystring?

Thank you

PS: I know there exist the backbone-query-parameters but I want to know just for backbone.

  • 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-08T11:22:49+00:00Added an answer on June 8, 2026 at 11:22 am

    You need to add another route with that expecting parameter :

    routes: {
        'posts?foo=:foo' : 'showPosts',
        'posts': 'showPosts'
    },
    showPosts: function (foo) {
        if(typeof foo != 'undefined'){
           // foo parameters was passed
        }
        test = true;
    }
    

    update
    You could define the general route to return all the query string and then parse it in the handler :

    routes: {
       'posts': 'showPosts',
       'posts?*queryString' : 'showPosts'
    },
    showPosts: function (queryString) {
        var params = parseQueryString(queryString);
        if(params.foo){
            // foo parameters was passed
        }
    }  
    ...
    // and the function that parses the query string can be something like : 
    function parseQueryString(queryString){
        var params = {};
        if(queryString){
            _.each(
                _.map(decodeURI(queryString).split(/&/g),function(el,i){
                    var aux = el.split('='), o = {};
                    if(aux.length >= 1){
                        var val = undefined;
                        if(aux.length == 2)
                            val = aux[1];
                        o[aux[0]] = val;
                    }
                    return o;
                }),
                function(o){
                    _.extend(params,o);
                }
            );
        }
        return params;
    }
    

    update 2

    Here’s a live demo to see the code in action.

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

Sidebar

Related Questions

I have a router setup like so: var AppRouter = Backbone.Router.extend({ routes: { /agents/:id:
My view is set up as below. simple. var ItemView = Backbone.View.extend({ tagName :
I have created a model in backbone.js. var Content = Backbone.Model.extend({ // If you
Posts.create({'body':post_body}); When I call that, Backbone will hit my sever with an AJAX post
When using Backbone Router it will treat a page route as #page. Can i
Currently I'm working on a Server-Client system which will be the backbone of my
I have a Backbone View for a general element that specific elements will be
I have noticed that when multiple attributes of a Backbone model are set like
Here is my application-router.js file where i'm creating Backbone.Router object with just only few
I'm new to Backbone.js. I have gone through the documentation. My question is where

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.