[英]Polymer 1.0: Controlling Access to or from a Route
Angular2 uses Route guard To control whether the user can navigate to or away from a given route,so if unauthorised user try to access a path route guard will protect. Angular2使用Route Guard来控制用户是否可以导航到或离开给定的路由,因此,如果未经授权的用户尝试访问路径,Route Guard将提供保护。
Is there any alternate way for route guard in polymer 1.0? 聚合物1.0中是否有其他替代方法可以保护线路? if not how it can be implemented?
如果没有,如何实施?
I don't know of any existing implementation, though it's always a good idea to search http://webcomponents.org , since one might pop up there any second. 我不知道任何现有的实现,尽管搜索http://webcomponents.org始终是一个好主意,因为一个人可能会在那儿突然弹出。
To implement this yourself, start by creating some kind of rights management behavior (or mixin class in Polymer 2) (which might query a web service for a map of {right1: Array<User>, ...}
; but don't forget about caching and so on...) which has a method checkRight(rightName, user)
. 要自己实现此目的,
{right1: Array<User>, ...}
创建某种权限管理行为(或Polymer 2中的mixin类)(它可能会在Web服务中查询{right1: Array<User>, ...}
的映射;但是不要忘记缓存等等),它具有方法checkRight(rightName, user)
。 You can then mix in that behavior/class to consuming elements, and bind the method checkRight
to any element you want to guard, for example an iron-pages' child's hidden
-attribute: 然后,您可以将该行为/类混合到消耗元素,并将方法
checkRight
绑定到要保护的任何元素,例如,铁页子元素的hidden
-attribute:
<dom-module id="my-app">
<template>
<iron-pages ...>
<my-page-1 hidden$="[[checkRight('right1', currentUser)]]"></my-page-1>
<my-page-2 hidden$="[[checkRight('right2', currentUser)]]"></my-page-2>
...
</iron-pages>
</template>
<script>
Polymer({
is: 'my-app',
properties: {
currentUser: {...}
},
behaviors: [My.RightsManagedBehavior]
});
</script>
</dom-module>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.