2017-08-13 7 views
1

パスのリストを持っていますCanActivateをいくつかのパスを除くすべてのパスに適用したいのですが、何らかのパスを破棄する方法があります。 現在、すべてのURLにcanActivateを適用しています。多くのURLがある場合、すべてのURLに適用したくない場合は、親のパスに適用します。 しかし、私たちが親に申請すると、それはすべての子供にも適用されます。子供たちの一部を捨てる方法はありますか?適用方法一部を除くすべてのパスにCanActivateを適用します

const routes: Routes = [ 
    { path : '', component: UsersListComponent, canActivate:[AuthenticationGuard] }, 
    { path : 'add', component : AddComponent, canActivate:[AuthenticationGuard]}, 
    { path : ':id', component: UserShowComponent }, 
    { path : 'delete/:id', component : DeleteComponent, canActivate:[AuthenticationGuard] }, 
    { path : 'ban/:id', component : BanComponent, canActivate:[AuthenticationGuard] }, 
    { path : 'edit/:id', component : EditComponent, canActivate:[AuthenticationGuard] } 
]; 
+0

ねえ、ソリューションはあなたのために機能しましたか? –

答えて

0

いくつかの子供たちを破棄することはできませんが、あなたはガードは、いくつかのではなく、いくつかに適用されるような方法であなたのルートを破ることが、

は、以下

{ 
    path: 'parentPath', 
    component: ParentComponent, 
    canActivate: [AuthGuard], 
    children: [ 
     {path : 'child1', component: ChildComponent1}, 
     {path : 'child2', component: ChildComponent2} 
    ] 
    }, 
    { 
    path: 'parentPath', 
    component: ParentComponent, 
    children: [ 
     {path : 'child3', component: ChildComponent3} 
    ] 
    } 

をお試しください上記のようなルートを設計した場合、Guradsはchild1child2にのみ適用され、child3には適用されません。

このようにして、一部の子供に対してGuardを親レベルで簡単に適用できます。

ここにはPlunkerです!

これが役立ちますように!

関連する問題