0

I am just wondering what is the best way to know which view to instantiate, in my application I have an individual view for each page and one master view which controls the generic functions and navigating between pages.

There are a couple of different ways that I could detect which page I am on and which view I should instantiate but I wanted some opinions on what others think is best.

So currently my options are:

  • To detect via URL
  • To detect via ID on containing element

If anyone has any better ideas that would be greatly appreciated.

Cheers.

UPDATE

I guess I could also add something like this on the HTML page:

<script>
    var page_one_view = new PageOneView();
</script>

With the correct view being instantiated on each HTML page, but this seems very messy.

lukehillonline
  • 2,430
  • 2
  • 32
  • 48

1 Answers1

1

I think that you are doing the wrong way, why ?

The backbone component that provides methods for routing client-side pages is Backbone.Router, take a look at the documentation

So if you use a view to manage your pages flow, you'll finish up re-implementing a new router with a diffrent approch.

Rida BENHAMMANE
  • 4,111
  • 1
  • 14
  • 25
  • Ah yes of course I completely forgot about the router, I am pretty new to backbone. Thanks. – lukehillonline Mar 03 '14 at 16:31
  • Can you look at this this page for me please, perhaps you can help me out. Thanks. http://stackoverflow.com/questions/22199059/backbone-router-not-working-on-page-load – lukehillonline Mar 05 '14 at 16:42