Reputation: 22478
I have a two routes with different hashes and same view model:
var routes = [
{ route: '', moduleId: 'home', title: 'Home', nav: 1 },
{ route: 'details(/:id)', moduleId: 'details', title: 'Details', nav: 2, hash: '#details' },
{ route: 'access_token=*token', moduleId: 'details', title: 'Details', nav: false, hash: "#access_token=" }];
How I can detect the way I came to details view model in activate
method of details view model? I tried to iterate over router.routes
array and find route with isActive() == true, but this doesn't available till activate method returns result.
Also, if I add detecting of active route into binding
method of view model, I getting both routes active, regardless of which route was applied:
function binding() {
router.routes.forEach(function (route) {
console.log('Route ' + route.hash + " isActive:" + route.isActive());
});
}
Console log:
Route # isActive:false details.js:37
Route #details isActive:true details.js:37
Route #access_token= isActive:true
Upvotes: 0
Views: 943
Reputation: 14995
Take a look at the router's activeInstruction property -
router.activeInstruction();
You can subscribe to it or create an computed off of it to track changes in the route.
Upvotes: 4