Route and subroute based on user in hottowel asp.net mvc4

你说的曾经没有我的故事 提交于 2019-12-11 15:08:28

问题


: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?


回答1:


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();


来源:https://stackoverflow.com/questions/21186048/route-and-subroute-based-on-user-in-hottowel-asp-net-mvc4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!