Angular - Sidebar not to show in Login but to show in Dashboard - Angular Routing

孤人 提交于 2019-12-20 04:37:23

问题


How to hide sidebar in login page?

How can I open login page first without sidebar and then after successful login will redirect on dashboard of template in Angular 4.


回答1:


The best way to do this is to design a Shell Component(suggested by Deborah Kurata in this ngConf talk) which will house your View After the user logs in.

The template of this Shell Component will house the Side Bar. The template of this Shell Component will also have a router-outlet for internal routing.

So your Routes config will look something like this:

const appRoutes: Routes = [
  {
    path: '',
    component: ShellComponent,
    children: [
      {
        path: 'dashboard',
        component: DashboardComponent
      },
      ...
      {
        path: 'view',
        component: ViewPostComponent
      },
      {
        path: '',
        component: PlaceholderComponent
      }
    ]
  },
  {
    path: 'login',
    component: LoginComponent
  },
  {
    path: '',
    redirectTo: '/login',
    pathMatch: 'full'
  }
];

Template for the Shell Component:

<!--Markup for your Sidebar here-->

<router-outlet></router-outlet>
<!--This router outlet is for Components that will load through child routing-->

Template for your App Component:

<router-outlet></router-outlet>

Here's a Sample StackBlitz for your ref.



来源:https://stackoverflow.com/questions/52793170/angular-sidebar-not-to-show-in-login-but-to-show-in-dashboard-angular-routin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!