생성:2026-06-22마지막 업데이트:2026-06-22
이 문서를 원하는 AI 어시스턴트에 참조하세요ChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
이 페이지와 원하는 AI 어시스턴트를 사용하여 문서를 요약합니다
버전 기록
- "usePathname 유틸리티 추가"v10.0.02026. 6. 23.
- "히스토리 초기화"v8.2.02026. 6. 22.
이 페이지의 콘텐츠는 AI를 사용하여 번역되었습니다.
영어 원본 내용의 최신 버전을 보기Edit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
Angular 통합: usePathname Hook 문서
usePathname 훅은 로케일 세그먼트가 제거된 현재 브라우저 경로를 Angular Signal<string>로 반환합니다. 이는 로케일 접두사를 수동으로 제거할 필요 없이, 예를 들어 어떤 내비게이션 항목이 활성화되었는지 파악하는 등 로케일을 고려한 내비게이션을 구축할 때 유용합니다.
Angular에서 usePathname 가져오기
typescript
코드 복사
코드를 클립보드에 복사
import { usePathname } from "angular-intlayer";개요
usePathname은 window.location.pathname을 읽고, getPathWithoutLocale을 통해 로케일 접두사를 제거하며, 브라우저가 popstate 이벤트(뒤로/앞으로 가기)를 발생시킬 때마다 시그널을 업데이트합니다. 컴포넌트가 파괴될 때 이벤트 리스너를 자동으로 정리하기 위해 Angular의 DestroyRef를 사용합니다.
사용법
src/app/nav-item.component.ts
코드 복사
코드를 클립보드에 복사
import { Component, input } from "@angular/core";import { usePathname } from "angular-intlayer";@Component({ standalone: true, selector: "app-nav-item", template: ` <a [href]="href()" [attr.aria-current]="pathname() === href() ? 'page' : null" > {{ label() }} </a> `,})export class NavItemComponent { readonly href = input.required<string>(); readonly label = input.required<string>(); readonly pathname = usePathname();}반환 값
테이블의 모든 내용 표시
테이블을 모달로 열어 모든 데이터를 명확하게 확인
| 타입 | 설명 |
|---|---|
Signal<string> | 로케일 접두사가 없는 현재 경로를 포함하는 Angular 시그널. |
동작
- 로케일 제거: 선행 로케일 세그먼트를 제거합니다 (예:
/ko/dashboard→/dashboard). - 반응형:
popstate이벤트(브라우저 뒤로 / 앞으로 탐색)에 자동으로 업데이트됩니다. - SSR 안전성:
window를 사용할 수 없을 때는""를 반환합니다. - 정리(Cleanup): 호스트 컴포넌트가 파괴될 때
DestroyRef.onDestroy를 통해popstate리스너가 제거됩니다.
예제
src/app/sidebar.component.ts
코드 복사
코드를 클립보드에 복사
import { Component } from "@angular/core";import { usePathname } from "angular-intlayer";@Component({ standalone: true, selector: "app-sidebar", template: ` <nav> @for (link of links; track link.href) { <a [href]="link.href" [style.font-weight]="pathname() === link.href ? 'bold' : 'normal'" > {{ link.label }} </a> } </nav> `,})export class SidebarComponent { readonly links = [ { href: "/dashboard", label: "대시보드" }, { href: "/settings", label: "설정" }, ]; readonly pathname = usePathname();}관련
useLocale— 현재 로케일 + 로케일 전환기getPathWithoutLocale— 이 훅에서 사용하는 기본 유틸리티