铁路由器路由允许/拒绝

编程入门 行业动态 更新时间:2024-10-24 16:24:43
本文介绍了铁路由器路由允许/拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我现在正在写一个流星应用程序,并习惯于新的Iron Router软件包(而不是我之前使用的路由器软件包)。

I'm writing a a meteor application right now, and am getting used to the new Iron Router package (as opposed to the router package that I used before).

我有一个路由集合,应该只能由具有特定属性的用户访问。具体来说,我使用Roles包。我目前的实现方法是定义一个before函数运行条件,并重定向到登录或错误页面,如果用户没有正确的角色。这里只是一个快速(coffeescript)示例:

I have a collection of routes that should only be accessible by users with specific properties. To be specific, I'm using the Roles package. My way of achieving this at the moment is to define a before function that runs a conditional, and redirects to a login or error page if the user doesn't have the proper role. Here's just a quick (coffeescript) example:

this.route 'home', path: '/' template: 'dashboard' before: -> unless Meteor.userId() this.redirect 'userUnauthorized' do this.stop

我的问题是,有更好的方法吗?看起来应该有一些方法来添加一个权限集,并将该权限集应用于路由,而不是为每个路由写入访问条件。

My question is, is there a better way to do this? It seems like there should be some way to add a permission set, and apply that permission set to a route as opposed to writing the access conditionals for every route.

推荐答案

您可以在路由中设置全局之前。我不是在我目前的应用程序中使用角色,但我们是根据他们是否登录,全球重定向用户。

You could setup a global "Before" in your routes. I'm not using roles in my current app, but we are redirect users globally based on whether or not they are signed in.

您可能会这样做:

Router.before(function() { unless(Meteor.userId()) { this.redirect('userUnauthorized'); do (this.stop) } }, {except: ['userUnauthorized', 'otherPageUnauthorizedUsersAllowedToSee']});

我们使用类似于 Router.configure c $ c>

We use something similar right below our Router.configure()

更多推荐

铁路由器路由允许/拒绝

本文发布于:2023-11-25 22:35:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   铁路

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!