티스토리 뷰
1. 이 포스트는 Email Client를 작성하는 시리즈의 일부이다
2. 이제 전반적인 라우팅을 정리해야 한다.
2-1 기본적으로 inbox와 auth 두 부분으로 나누어져 있다.
2-2 /inbox는 이메일 모듈이 로딩되도록, /auth에는 인증모듈이 실행되도록 한다.
2-3 '' 루트의 경우 Home 컴포넌트가 보여질도록 한다.
3. 루트 경로에서 보여질 페이지가 필요하다.
3-1 첫 페이지에서 보여질 Home 컴포넌트를 하나 생성한다.
3-2 일치하지 않는 경로를 입력했을 때를 위해서 NotFound 컴포넌트도 하나 생성한다.
3-3 그냥 지금 app template에 있는 콘텐츠 부분의 값을 cut해서 복사했다.
<p>
These steps were used to create this responsive navbar.
</p>
<ol>
<li>
Add a property to the component to track whether the menu is open.
In this example, the property is called <code>isMenuCollapsed</code>.
</li>
<li>
Add an <code>ngbCollapse</code> directive to the element
with the <code>navbar-collapse</code> CSS class. Use the
property in the component as the value for the directive.
</li>
<li>
When the navbar toggler button is clicked, toggle the
value of the property in the component.
</li>
<li>
If you would like the menu to close when a link is clicked,
add a <code>(click)</code> handler to each link and set the
property on the component to true to hide the menu.
</li>
</ol>
<p>
Resize your browser window to see it in action!
</p>
3-4 이제 app template에 라우팅 페이지를 보여줄 router-outlet을 지정한다.
3-4-1 각 메뉴에는 적절한 url을 입력한다.
3-4-2 inbox를 누르면 /inbox로 간다.
3-4-3 SignOut 버튼은 /auth/signOut, SignIn 버튼은 /auth/signIn, SignUp은 /auth/signUp으로 연결된다.
3-4-4 각 경로에는 activeLinkActive 속성이 지정되어 활성화 된 경로를 표시하도록 하였다.
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-3">
<a class="navbar-brand" [routerLink]="'.'">
EM<i class="fas fa-paper-plane bg-dark text-white m-0"></i>IL
</a>
<!-- Step 3: Toggle the value of the property when the toggler button is clicked. -->
<button class="navbar-toggler" type="button" (click)="isMenuCollapsed = !isMenuCollapsed">
☰
</button>
<!-- Step 2: Add the ngbCollapse directive to the element below. -->
<div [ngbCollapse]="isMenuCollapsed" class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item">
<!-- Step 4: Close the menu when a link is clicked. -->
<a class="nav-link" [routerLink]="'/inbox'" (click)="isMenuCollapsed = true"
[routerLinkActive]="'active'">Inbox</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<!-- Step 4: Close the menu when a link is clicked. -->
<a class="nav-link" [routerLink]="'/auth/signOut'" (click)="isMenuCollapsed = true"
[routerLinkActive]="'active'" *ngIf="signedIn$ | async">Sign Out</a>
</li>
<ng-container *ngIf="!(signedIn$ | async)">
<li class="nav-item">
<a class="nav-link" [routerLink]="'/auth/signUp'" (click)="isMenuCollapsed = true"
[routerLinkActive]="'active'">Sign Up</a>
</li>
<li class="nav-item">
<a class="nav-link" [routerLink]="'/auth/signIn'" (click)="isMenuCollapsed = true"
[routerLinkActive]="'active'">Sign In</a>
</li>
</ng-container>
</ul>
</div>
</nav>
<div class="container">
<router-outlet></router-outlet>
</div>
4. 루트 라우팅 테이블 설정이다.
4-1 인증과 이메일 모듈은 둘다 lazy loading 방식으로 처리한다.
4-2 루트 경로가 지정되면 프로그램 전체 Landing 페이지인 home 컴포넌트가 로딩된다.
4-3 경로 매핑이 없는 경우는 NotFound 컴포넌트를 보여준다.
4-4 아래의 매핑 테이블은 프로젝트 생성 시에 --routing 옵션을 주어 기본적으로 app.module.ts에 import 되어 있다.
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { NotFoundComponent } from './not-found/not-found.component';
const routes: Routes = [
{ path: 'auth', loadChildren: ()=> import('./auth/auth.module').then(module=> module.AuthModule )},
{ path: 'inbox', loadChildren: ()=> import('./email/email.module').then(module=> module.EmailModule )},
{ path: '', component: HomeComponent },
{ path: '**', component: NotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
5. email, auth 모듈의 동적 라우팅 테이블을 설정한다.
5-1 각 모듈 마다 라우팅 모듈을 설정하고, 그 라우팅 모듈을 모듈파일에 import 시킨다.
5-2 처음 생성할 때 --routing 을 빼 먹어 파일을 생성해 주어야 한다.
5-2-1 email-routing.module.ts와 auth-routing.module.ts 파일을 생성하고 라우팅을 지정한다.
5-2-2 각 모듈의 모듈 파일에 라우팅 테이블을 import한다.
5-3 email-routing 설정하기
5-3-0 아래의 코드는 email-routing.module.ts 파일이다.
5-3-1 email은 경로 선택시에 첫 포스트에서 생성한 Home 컴포넌트가 표시되도록 한다. 루트의 Home과 다르다.
5-3-2 Home을 만든 이유는 이메일 페이지는 목록과 콘텐츠로 구분되어 하나 이상의 컴포넌트가 표시되는데,
5-3-2-1 그런 컴포넌트를 담는 container로 동작할 것이다.
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
const routes: Routes = [
{ path: '', component: HomeComponent },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class EmailRoutingModule { }
5-3-2 위에서 설정한 routing 모듈을 email.module.ts에 등록해야 한다. 생성 시 --routing을 빠뜨려 수동으로 한다.
5-3-2-1 import에 라우팅 모듈을 추가한다.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomeComponent } from './home/home.component';
import { EmailRoutingModule } from './email-routing.routing.module';
@NgModule({
declarations: [HomeComponent],
imports: [
CommonModule,
EmailRoutingModule
]
})
export class EmailModule { }
5-4 보안 모듈도 같은 작업을 한다.
5-4-1 보안 라우팅 모듈을 생성하고 아래처럼 작성한다.
5-4-1-1 여기에서는 기본 컴포넌트가 필요없다. 한 페이지 한 컴포넌트를 사용할 예정이다.
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SignUpComponent } from './sign-up/sign-up.component';
import { SignInComponent } from './sign-in/sign-in.component';
const routes: Routes = [
{ path: 'signUp', component: SignUpComponent },
{ path: 'signIn', component: SignInComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AuthRoutingModule { }
5-4-3 이메일 모듈에서 한 것처럼 이 라우팅 모듈을 보안 모듈에 등록한다.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SignInComponent } from './sign-in/sign-in.component';
import { SignUpComponent } from './sign-up/sign-up.component';
import { AuthRoutingModule } from './auth.routing.module';
@NgModule({
declarations: [SignInComponent, SignUpComponent],
imports: [
CommonModule,
AuthRoutingModule
]
})
export class AuthModule { }
6. 경로에 따른 페이지들이다.
6-1 루트 페이지 - 루트 경로로 진입하면 루트의 Home 컴포넌트가 표출된다.
6-2 /inbox - inbox로 가면 inbox 모듈의 Home 컴포넌트가 로딩된다.
6-3 /auth/signUp - Sign Up 버튼을 눌렀을 경우이다. auth 모듈의 SignUp 컴포넌트가 표출된다.
6-4 /auth/SignIn - Sign In 버튼을 눌렀을 경우이다. auth 모듈의 SignIn 컴포넌트가 화면에 나온다.
'Demos > Email Client' 카테고리의 다른 글
Angular : Email Client - 1-5. 인증모듈작성 - Sign up, Sign in Template과 Form Control 작성하기 (0) | 2020.06.22 |
---|---|
Angular : Email Client - 1-4. 인증모듈작성 - email 모듈 guard 작성하기 (0) | 2020.06.22 |
Angular : Email Client - 1-2. 인증모듈작성 - 로그인 상태 관리 (0) | 2020.06.22 |
Angular : Email Client - 1-1. 인증모듈작성 - ng-bootstrap 반응형 메뉴바 작성 (0) | 2020.06.22 |
Angular : Email Client - 1. 프로젝트 생성 (0) | 2020.06.22 |
- Total
- Today
- Yesterday
- 도커 개발환경 참고
- AWS ARN 구조
- Immuability에 관한 설명
- 자바스크립트 멀티 비동기 함수 호출 참고
- WSDL 참고
- SOAP 컨슈머 참고
- MySql dump 사용법
- AWS Lambda with Addon
- NFC 드라이버 linux 설치
- electron IPC
- mifare classic 강의
- go module 관련 상세한 정보
- C 메모리 찍어보기
- C++ Addon 마이그레이션
- JAX WS Header 관련 stackoverflow
- SOAP Custom Header 설정 참고
- SOAP Custom Header
- SOAP BindingProvider
- dispatcher 사용하여 설정
- vagrant kvm으로 사용하기
- git fork, pull request to the …
- vagrant libvirt bridge network
- python, js의 async, await의 차이
- go JSON struct 생성
- Netflix Kinesis 활용 분석
- docker credential problem
- private subnet에서 outbound IP 확…
- 안드로이드 coroutine
- kotlin with, apply, also 등
- 안드로이드 초기로딩이 안되는 경우
- navigation 데이터 보내기
- 레이스 컨디션 navController
- raylib
- Spring
- 매핑
- mapping
- jsp
- Security
- form
- Spring Security
- 설정
- crud
- 하이버네이트
- one-to-one
- Many-To-Many
- login
- RestTemplate
- Rest
- 자바
- Angular
- 설정하기
- Validation
- 로그인
- 스프링
- hibernate
- spring boot
- WebMvc
- 외부파일
- XML
- one-to-many
- MYSQL
- 스프링부트
- 상속