Sub routing in a SPA site

Posted by Anders on Programmers See other posts from Programmers or by Anders
Published on 2013-10-24T07:27:08Z Indexed on 2013/10/24 10:10 UTC
Read the original article Hit count: 408

I have a SPA site that I'm working on, I have a requirement that you can have subroutes for a page view model. Im currently using this 'pattern' for the site

MyApp.FooViewModel = MyApp.define({
    meta: {
        query: MyApp.Core.Contracts.Queries.FooQuery,
        title: "Foo"
    },
    init: function (queryResult) {

    },
    prototype: {               
    }
});

In the master view model I have a route table

this.navigation(new MyApp.RoutesViewModel({
    Home: {
        model: MyApp.HomeViewModel,
        route: String.empty
    },
    Foo: {
        model: MyApp.FooViewModel
    }
}));

The meta object defines which query should populate the top level view model when its invoked through sammyjs, this is all fine but it does not support sub routing

My plan is to change the meta object so that it can (optional offcourse) look like this

meta: {
    query: MyApp.Core.Contracts.Queries.FooQuery,
    title: "Foo",
    route: {
        barId: MyApp.BarViewModel
    }
}

When sammyjs detects a barId in the query string the Barmodel will be executed and populated through its own meta object.

Is this a good design?

© Programmers or respective owner

Related posts about web-development

Related posts about JavaScript