簡體   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