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

  • Home
  • SEARCH
  • 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 8937273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:22:39+00:00 2026-06-15T10:22:39+00:00

I’m developing my first backbone project and I have requirement that I’m not sure

  • 0

I’m developing my first backbone project and I have requirement that I’m not sure how to meet. I’m sure the solution has something to do with properly routing my app, but I’m not sure…

App.Router = Backbone.Router.extend({
        initialize: function(options) {
            this.el = options.el;
        },
        routes: {
            '': 'search',
            'search': 'search'
        },
search: function() {
            var search = new App.SearchView();
            search.render();
        }
}
    });

I have three views:

// Defines the View for the Search Form
App.SearchView = Backbone.View.extend({

    initialize: function() {
        _.bindAll(this, 'render');
        this.render();
    },

    template: _.template($('#search-form').html()),
    el: $('#search-app'),
    events: {
        'click .n-button' : 'showResults'
    },

    showResults: function() {
        this.input = $('#search');
        var search = new App.ResultsSearchView();
        var grid = new App.GridView({ query: this.input.val() });
        search.render();
        grid.render();
    },

    render: function() {
        $(this.el).html(this.template());
        return this;
    },
    name: function() { return this.model.name(); }

}); // App.SearchView

//Defines the View for the Search Form when showing results
App.ResultsSearchView = Backbone.View.extend({

    initialize: function() {
        _.bindAll(this, 'render');
        this.render();
    },  
    template: _.template($('#results-search-form').html()),
    el: $('#search-input'), 
    render: function() {
        $(this.el).html(this.template());
        return this;
    },
    events: {
        'click .n-button' : 'showResults'
    },
    showResults: function() {
        this.input = $('#search');
        var grid = new App.GridView({ query: this.input.val() });
        grid.render();
    },
    name: function() { return this.model.name(); }

}); // App.ResultsSearchView


// Defines the View for the Query Results
App.GridView = Backbone.View.extend({
    initialize: function(options) {
        var resultsData = new App.Results();
        resultsData.on("reset", function(collection) {

        });

        resultsData.fetch({
            data: JSON.stringify({"query":this.options.query, "scope": null}),
            type: 'POST',
            contentType: 'application/json',
            success: function(collection, response) {
                $('#grid').kendoGrid({
                    dataSource: {
                        data: response.results,
                        pageSize: 5
                    },
                    columns: response.columns,
                    pageable: true,
                    resizable: true,
                    sortable: {
                        mode: "single",
                        allowUnsort: false
                    },
                    dataBinding: function(e) {

                    },
                    dataBound: function(){

                    }
                });

            },
            error: function(collection, response) {
                console.log("Error: " + response.responseText);
            }


        });
        _.bindAll(this, 'render');
        this.render();
    },
    el: $('#search-app'),
    template: _.template($('#results-grid').html()),
    render: function() {
        $(this.el).html(this.template());
        return this;
    }
}); // App.GridView

The issue I am having is that we want our users to be able to use the back button to navigate back to the initial search and also from there, be able to move forward again to their search results. I just have no idea how to do this. Any assistance would be a huge help.

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-15T10:22:40+00:00Added an answer on June 15, 2026 at 10:22 am

    Backbone handles the browser history — all you have to do is call Backbone.history.start() on startup. Well, that and make sure to call Router.navigate whenever you want to save the current navigation state.

    In your example, the appropriate time would be when the user clicks “search”. In the searchView.showResults method, instead of creating and rendering the results view, call:

    myRouter.navigate("results/" + this.input.val(), { trigger: true });
    

    This causes the router to go to the results/query route, which you have to add:

    'results/:query': 'results'
    

    Finally, create the results method within your router, and put the view-creating logic there:

    results: function(query) {
        var search = new App.ResultsSearchView();
        var grid = new App.GridView({ query: query });
        search.render();
        grid.render();
    }
    

    • Here’s a working demo — it’s a bit hard to see on JSFiddle because the page is within an iFrame, but you can confirm it’s working by hitting Alt+Left, Alt+Right to call the browser’s back and forward respectively.

    • And for contrast, here’s a similar demo, except it uses a single route. It calls router.navigate without trigger: true. You can see that, using this single-route method, you’re able to navigate back; however, you can’t go forward again to the results view, because Backbone has no way to re-trace the steps to get there.

    App

    var HomeView = Backbone.View.extend({
        initialize: function() {
            this.render();
        },
        el: "#container",
        events: {
            "submit #search": "search"
        },
        template: _.template($("#search-template").html()),
        render: function() {
            var html = this.template();
            this.$el.html(html);
        },
        search: function(e) {
            e.preventDefault();
            router.navigate("results/" + $(e.target).find("[type=text]").val(), { trigger: true });
        }
    });
    
    var ResultsView = Backbone.View.extend({
        initialize: function() {
            this.render();
        },
        el: "#container",
        render: function() {
            var html = "Results test: " + this.model.get("query");
            this.$el.html(html);
        }
    });
    
    var Router = Backbone.Router.extend({
        routes: {
            "" : "search",
            "results/:query": "results"
        },
    
        search: function() {
            console.log("search");
            var v = new HomeView();
        },
        results: function(query) {
            console.log("results");
            var v = new ResultsView({ model: new Backbone.Model({ query: query }) });
        }       
    });
    var router = new Router();
    Backbone.history.start();
    

    HTML

    <script type='text/template' id='search-template'>
        <form id="search">
        <input type='text' placeholder='Enter search term' />
        <input type='submit' value='Search' />
        </form>
    </script>
    
    <div id="container"></div>​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I have an array which has BIG numbers and small numbers in it. I
I need a function that will clean a strings' special characters. I do NOT
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.