Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top