繁体   English   中英

使AuthenticatedRouteMixin内的嵌套路由可访问

[英]Make nested route inside AuthenticatedRouteMixin accessible

我想“释放”一条嵌套路由,以便甚至没有登录的用户也可以访问此路由。

例如:

posts - /create - /edit - /show

posts路线上,我使用了AuthenticatedRouteMixin 这样,所有子路由都会自动受到保护。 现在,我只想使/show访问。 我知道我可以在/create/edit上使用一个mixin并将其从posts路由中删除,但是如果您有10条以上的嵌套路由,并且其中只有1条对于未登录的用户也应该可用,这是一种不便。

您是否知道其他解决方案?

如果没有,我想我必须为此写一个额外的mixin。

谢谢!

ember-simple-auth的AuthenticatedRouteMixin使用beforeModel挂钩来检查session.isAuthenticated。 您需要在“显示”路由中覆盖beforeModel,以绕过AuthenticatedRouteMixin的super()实现来跳过Auth检查。

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

检查“ show” beforeModel是否与父路由相关,即“ posts”,在父路由上执行此检查。

您可以使用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