Router State trong Angular là gì?
Router State trong Angular là gì?
Router state trong Angular là trạng thái hiện tại của router: một cây các route đang được kích hoạt (ActivatedRoute), tương ứng với URL hiện tại. Mỗi node của cây chứa thông tin của một đoạn route: tham số (params), query params, fragment, data, dữ liệu từ resolve, component và outlet tương ứng.
URL: /users/42/orders?status=paid
RouterState (cây ActivatedRoute)
└── '' → AppComponent
└── 'users/:id' → UserComponent params: { id: '42' }
└── 'orders' → OrdersComponent queryParams: { status: 'paid' }
import { Router, ActivatedRoute } from '@angular/router';
export class OrdersComponent {
private router = inject(Router);
private route = inject(ActivatedRoute);
ngOnInit() {
const state = this.router.routerState; // RouterState: cây đầy đủ, dạng Observable
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.