szalishchuk / generator-spa

Yeoman generator for fast Single Page Application prototyping with PhoneGap integration.
MIT License
4 stars 1 forks source link

if subroute ends with an id #32

Open szalishchuk opened 10 years ago

szalishchuk commented 10 years ago

At this point we parse the url and with each slash we delegate the responsibility for further actions to the corresponding subrouter.

The problem is that when we have a url that ends up with an id, subrouter will fail to evaluate that. Specifying :id in subrouter.routes object does not help subrouter to determine that this should be handled as a parameter and not a sub page.

As of now, we handle this use case with using a custom implementation of subrouter, which does not have subrouter.invokePageModule() method.

Example:

url: "~/profile/1231212"
var ProfileRouter = Backbone.PageRouter.extend({
            routes: {
                 '': 'injectIndexPage'
                ,':id': 'injectIndexPage'
            }
            ,injectIndexPage: function(id) {
                var self = this;
                // Set the pageView container as an $el for this obj
                this.$el = this.$el || $('.page-wrap');
                // Instantiate ApplicationPageView only once
                if(!this.pageView) this.pageView = new this.options.index({ id: id });
                // Detach all the other contents from the DOM
                // and preserve event binders with .detach()
                this.$el.contents().detach();
                // Inject it into the DOM
                this.$el.append(this.pageView.$el);
                // Trigger pageChange event to notify corresponding view to act
                // appropriately (e.g. close navigation bar)
                Eva.trigger('page:change', this.pageView);
                this.pageView.on('remove', function() {
                    self.pageView = null;
                });
            }
            ,options: {
                index: IndexPage
            }
});

We should find a way to handle this gracefully.