Angular2: Using routes, how to display the navigation bar after successfully logged in?

前端 未结 3 1634
孤街浪徒
孤街浪徒 2020-12-13 07:05

I\'m trying to show the navigation bar, once the user successfully do.

For example:

How To Change \"showMenu\" property in \"AppComponent\" inside the \"Logi

3条回答
  •  不知归路
    2020-12-13 07:30

    best modern way in angular4, with new router, with children routes, just needed use UrlSerializer-class to remove parenthesis, https://angular.io/docs/ts/latest/api/router/index/UrlSerializer-class.html, anyone did uses it?

    export const ROUTES: Routes = [
      { path: 'login', component: LoginComponent },
      {
        path : '',
        children: [
            {
              path: '', component: DefaultLayoutComponent,
              children: [
                { path: '', component: HomeComponent, canActivate: [AuthGuard] },
                { path: 'users', component: UsersListComponent, canActivate: [AuthGuard] },
                { path: 'users-add', component: UsersAddComponent, canActivate: [AuthGuard] },
                { path: 'users-view/:id', component: UsersViewComponent, canActivate: [AuthGuard] },
                { path: 'users-edit/:id', component: UsersEditComponent, canActivate: [AuthGuard] },
                ]
            }
        ]
      },
      // otherwise redirect to home
      { path: '**', redirectTo: '' }
    ]
    

提交回复
热议问题