2017-02-10 111 views
0

我想實現一個角度2到我的項目中的用戶認證包:http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial角2路由器:孩子沒有siplayed

我把整個文件夾放入名爲「loginMGR」的超級文件夾,在模塊,組件和文件名中將「app」改名爲「loginMGR」,並將app-routing.module(現名爲loginMGR.module)更改爲:

imports... 

const loginRoutes: Routes = [ 
    { 
    path: '', 
    component: HomeComponent, 
    canActivate: [AuthGuard], 
    children: [ 
     { path: 'identification', component: LoginComponent }, 
     { path: 'enregistrement', component: RegisterComponent }, 
    ] 
    }, 

    // otherwise redirect to home 
    { path: '**', redirectTo: '' } 
]; 

@NgModule({ 
    imports: [ 
    RouterModule.forChild(loginRoutes) 
    ], 
    exports: [ 
    RouterModule 
    ] 
}) 

export class LoginRoutingModule 

我的應用程序路由採用下列路線模塊名稱的鏈接:

const routes: Routes = [ 
... 
     { path: 'authentification', component: LoginMGRComponent }, 
... 

我訪問束感謝這個按鈕:

<a [routerLink]="['/authentification']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}" class="navbar-link"> 

但是,router-outlet和我的loginMGR.component.html的警報保持爲空,並且不鏈接到它們應該訪問的不同組件(在這種情況下,「'將會是」home「)。

任何想法我做錯了什麼?

謝謝

回答

1

既然你在LoginRoutingModule定義你的孩子的路線,只需要導入您的應用程序模塊中,並刪除應用模塊路由的路由。

+0

就是這樣!謝謝。而且,我沒有提到整個文件,我應該這樣做。我的AppRoutingModule導入在阻止聲明的LoginRoutingModule之前。 – Callehabana