简体   繁体   English

使AuthenticatedRouteMixin内的嵌套路由可访问

[英]Make nested route inside AuthenticatedRouteMixin accessible

I'd like to "free" one nested route, so that also users who are not even logged in can access this route. 我想“释放”一条嵌套路由,以便甚至没有登录的用户也可以访问此路由。

For example: 例如:

posts - /create - /edit - /show

On the posts route I used the AuthenticatedRouteMixin . posts路线上,我使用了AuthenticatedRouteMixin With this, all sub routes are automatically protected. 这样,所有子路由都会自动受到保护。 Now I only want to make /show accessable. 现在,我只想使/show访问。 I know that I could use a mixin on /create and /edit and remove it from posts route, but if you have 10+ nested routes and only 1 of them should be available also for not logged in users, it's kind of inconvenient. 我知道我可以在/create/edit上使用一个mixin并将其从posts路由中删除,但是如果您有10条以上的嵌套路由,并且其中只有1条对于未登录的用户也应该可用,这是一种不便。

Do you know any other solution to that challenge? 您是否知道其他解决方案?

If not, I think I have to write an additional mixin for that... 如果没有,我想我必须为此写一个额外的mixin。

Thanks! 谢谢!

ember-simple-auth's AuthenticatedRouteMixin uses beforeModel hook to check whether session.isAuthenticated or not. ember-simple-auth的AuthenticatedRouteMixin使用beforeModel挂钩来检查session.isAuthenticated。 You need to override the beforeModel in 'show' route to either skip the Auth check by bypassing AuthenticatedRouteMixin's super() implementation all together. 您需要在“显示”路由中覆盖beforeModel,以绕过AuthenticatedRouteMixin的super()实现来跳过Auth检查。

beforeModel (transition, skipAuthCheck) {
    if (!skipAuthCheck) {
       return this._super(...arguments, true);
    }
}

Check if the 'show' beforeModel has dependency with parent route .ie 'posts', implement this check at the parent route. 检查“ show” beforeModel是否与父路由相关,即“ posts”,在父路由上执行此检查。

You could fake a nested route, by using the path parameter: 您可以使用path参数来伪造嵌套路由:

this.route('posts', function() {
    this.route('create');
    this.route('edit');
});
this.route('posts-show', { path: '/posts/show' });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM