Question

:updated

can anyone help me found out how to create routes and subroute based on user is it possible to create a Widget that will do the job if so how

this is how my menu looks like (note:all menu items together let us call it master):

-Home
-shop
    -men
    -women
-food
    -dog
    -human
-cart
-settings
    -user
    -images
    -themes

let say i have the following userGroup:

-Admin
-visitors
-vip
-costumers
-co-workers

what i want to do ist some thing like

if(user == Admin){
   destroy the current menu then make a copy of master **master** remove subroute women and subroute dog then push 
}else if(user == visitor){
   ...
}

or is there a better way to do this and where i am supose to define it?

Was it helpful?

Solution

First you might want to consider upgrading your project to Durandal 2.0 since it removes the dependency on sammy.js in favor of a custom router which works much better (Durandal 1.0 is essentially obsolete now). Here is the page on upgrading: http://durandaljs.com/documentation/Conversion-Guide/

and here are the docs on the new router: http://durandaljs.com/documentation/Using-The-Router/

As for handling the routing based on user, since router.map just expects an array of routes you can just build up the array conditionally and pass it to router.map

var routes = [ { route: '', moduleId: 'hello/index', title: 'Hello World', nav: true },
            { route: 'men', moduleId: 'men/index', title: 'Men',  nav: true }]
if(user == Admin){
    routes.push({ route: 'admin', moduleId: 'admin/index', title: 'Admin',  nav: true }
}else if(user == visitor){
    routes.push({ route: 'women', moduleId: 'women/index', title: 'women',  nav: true }
}
return router.map(routes)
          .buildNavigationModel()
          .mapUnknownRoutes('hello/index', 'not-found')
          .activate();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top