Sub routing in a SPA site
- by Anders
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?