易学问答
  • 首页
  • 话题
  • 动态
  • 专家
  • 文章
  • 作者
  • 公告
  • 更多
    • 积分规则
登录 或 注册
  • 首页
  • 话题
  • 动态
  • 专家
  • 文章
  • 作者
  • 公告
  • 积分规则
 发表新帖
发表新帖

How to use separate layout for login component in angular 2?

后端 未结
关注
 2  1908
滥情空心
滥情空心 2021-01-01 23:23

I am new in angular. I create a login component , it works fine fine but issue is that I want a separate layout of login from whole app. What changes required for that?

2条回答
  •  误落风尘
    误落风尘 (楼主)
    2021-01-01 23:32

    In your app.component.html:

    
    

    Then create MainComponent (main.component.ts) and put all of your main app layout in main.component.html:

    
    

    This component will be parent for each your regular app component.

    Then in your LoginComponent put different layout without router-outlet, for example:

    ... your login layout

    Then modify your routing to be something like that:

    const appRoutes: Routes = [
      {path: 'login', component: LoginComponent},
      {path: '', component: MainComponent, redirectTo: '/dashboard', pathMatch: 'full',
        children: [
          { path: 'alert/:id', component: AlertDetailComponent },
          { path: 'alerts', component: AlertsComponent },
          { path: 'dashboard', component: EriskDashboardComponent }
      ]}];
    

    So MainComponent will contain all reusable layouts and app structure for any child component, while LoginComponent is independent and it has its own layout.

    0 讨论(0)
    查看其它2个回答
    提交评论

    •  加载中...
 看不清?
提交回复
热议问题